Advertisements
The following command will create a compressed tar
archive for each folder found in the current directory.
It will use the LZMA/LZMA2 compression algorithms and it supports Unix-like file system metadata as well.
It will reuse the name of the folder for the archive as well and it will append the current date to the name.
find . -maxdepth 1 -mindepth 1 -type d -exec tar cJf "{}.`date +%F`.tar.xz" '{}' \;
The parameters we used for the find
command are the following:
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the command line arguments.-maxdepth 0
means only apply the tests and actions to the command line arguments.-mindepth levels
Do not apply any tests or actions at levels less than levels (a non-negative integer).-mindepth 1
means process all files except the command line arguments.-type d
Match directories (folders) only
The parameters we used for the tar
command are the following:
-c
create a new archive-J
filter the archive throughxz
(compress the archive using thexz
lossless compression program)-f
file use archive named file