Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

share|improve this question
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? – John S Gruber Aug 22 '12 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. – Steve Kroon Aug 22 '12 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? – Steve Kroon Aug 23 '12 at 7:05

From the tar(1) man page:

          avoid descending automatically in directories
share|improve this answer
: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? – stephenmyall Aug 22 '12 at 12:22
tar --no-recursion ... It will solve it because tar will not recurse subdirectories. – Ignacio Vazquez-Abrams Aug 22 '12 at 14:38

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.