44

Is there a fairly simple way to tar several (specific) files in a directory? For example let's say the following is a directory:

-rw-r--r-- 1 allend bin     98 Jul 20 15:50 scriptlog.log
-rw-r--r-- 1 allend bin  19533 Jul 29 21:47 serveralert.log
-rwxr--r-- 1 allend bin   1625 Jul 29 21:47 orion
-rw-r--r-- 1 allend bin  24064 Jul 29 21:49 orion_files.tar
-rwxr--r-- 1 allend bin    156 Aug  4 21:22 htmltest
-rw-r--r-- 1 allend bin    131 Aug  4 21:23 page.html

What if I only want to tar the files serveralert.log and page.html?

Joseph R.
  • 39,549
AllenD
  • 2,467

1 Answers1

79

Is there something wrong with listing the files you'd like to add to the .tar file?

$ tar cvf some.tar file1 file2 file3

Example

$ tar cvf some.tar serveralert.log page.html
serveralert.log
page.html
slm
  • 369,824
  • 3
    I see. I found out what the problem was with your help. I had been adding an "-" to tar options. This was causing it not to work for me. I'm sorry it seemed that I had not done any research on this matter. Thank you very much for your help in this matter. – AllenD Aug 06 '13 at 01:57
  • You could also compress all files using pattern matching. E.g. tar cvf *.csv – ahmadabdulnasir Nov 26 '20 at 11:17
  • If you have too many files and you end up with a Argument list too long error then you can use find instead. See this answer on SuperUser. – Florian Brucker Feb 10 '21 at 13:12