0

what I am trying to do is to compress a list of files using tar.

So what I am doing is

sudo tar -pcf filename.tgz `cat filename.list`

so if there is a directory on the list like this

/home/vmuser/.gconf

tar compresses everything in that folder. However what I want is to just add exactly whatever is on the list.

3
  • Sorry, but I'm not clear on why you don't just take the directory name off filename.list if you don't want that directory's contents to be tar'ed. What am I missing? Aug 22, 2012 at 5:02
  • Note that tar does not actually compress files, it just puts them all into one file (this is called archiving the files). Just naming the output file .tgz will not cause the file to be compressed - you will also need to use the z flag (i.e. tar pczf filename.tgz) which compresses the resulting tar file using gzip. Aug 22, 2012 at 9:13
  • Do you want to tar the info in the folder inode, or do you just want to skip folders in the file list? Aug 23, 2012 at 7:05

2 Answers 2

2

If you want to tar all files listed in filename.list, you should use the tar -T filename.list command rather than tar 'cat filename.list'.

From the tar manpage:

 -T, --files-from FILE
       get names to extract or create from FILE

Using -T will prevent you from getting the error:

-bash: /bin/tar: Argument list too long

if you try to compress a large number of files.


In order to prevent recursive compression of directories, use the --no-recursion flag, as suggested by @Ignacio Vazquez-Abrams. The final command becomes:

tar -pcf filename.tgz -T filename.list --no-recursion
0

From the tar(1) man page:

   --no-recursion
          avoid descending automatically in directories
2
  • :I am not clear on the answer you gave. Can you edit your response to include the instructions needed to answer the question, and maybe sugeest how this will resolve it? Aug 22, 2012 at 12:22
  • tar --no-recursion ... It will solve it because tar will not recurse subdirectories. Aug 22, 2012 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .