How to create a zip file from contents of a folder with certain name pattern?
is it possible to create a tar.gz
file from contents of a folder but only put the files with certain name pattern in the archive and ignore the rest? for example just put the files which their names are log_?
Example Using zip(you can choose any other compression tool instead):
find /path-to-dir -name 'log_*' | zip archive.zip -@
example:
$ ls
file log_1 log_2 log_3
Now zip all files log_* in zipped called archive.zip
$ find . -name 'log_*' | zip archive.zip -@
adding: log_1 (stored 0%)
adding: log_3 (stored 0%)
adding: log_2 (stored 0%)
Now let's check output:
$ ls
archive.zip file log_1 log_2 log_3
You can use tar
directly:
tar -zcvf file.tar.gz log_*