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_?


You can use tar directly:

tar -zcvf file.tar.gz log_*
  • it seems to be simplest way – MoienGK Jun 23 '15 at 13:12

Example Using zip(you can choose any other compression tool instead):

find /path-to-dir -name 'log_*' | zip archive.zip -@


$ 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

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.