Reputation: 269
I have a folder, called webseiten
with different subfolders.
I want those subfolders to be tar'd. Name of those tars should be the name of the subfolder that gets tar'd.
How can I do that?
My guess is:
find webseiten/ -type d -exec tar -cfvz
- but whats now? How to pass the desired output name to exec?
As it seems to be a little odd what I want to achieve:
I don't want one big Tar with all subfolders in it. I want a tar for each subfolder in my main folder.
So basically:
Content of webseiten
:
folder-1
folder-2
folder-3
folder-4
Then the output should be folder-1.tar.gz
, folder-2.tar.gz
, folder-3.tar.gz
and folder-4.tar.gz
.
Upvotes: 0
Views: 117
Reputation: 58858
cd webseiten
for dir in */
do
tar -czf "$(basename "$dir").tar.gz" "$dir"
done
That is literally it. For more information, man tar
(and man find
).
Upvotes: 1