I have a folder with a few folders and files.

The name of folders is a date. like: 2020-01-16.

I want to tar only and every folder in this directory, and then delete that folders after tar successfully, and the name of the tar files is the name of the own folders. And I want to skip today folder and not tar that.


Here is what I would do, in two steps per folder:

tar -zcvf 2020-01-16.tar.gz 2020-01-16

rm -rf 2020-01-16

and repeat for each folder you have. If you wanted to do this in a script to tar everything you need at once you could, but I personally wouldn't; I would rather make sure each tar.gz folder tarred successfully before deleting the untarred folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.