When using tar for backups I'd like to create a separate list of the files that is included in the archive for storing alongside the backup tarball.

I also want to be able to store the error messages from tar in a log.

Solutions that's not so good:

  • tar --verbose ... &> filelist.txt But this would give errors + file list in one file.
  • tar --list after the tarball has been created. But this takes a long time.

Is there some way to get the file list and store it in a separate file at the same time as I'm rolling the ball for the first time?

  • how do you specify the files to tar?
    – Jasper
    Apr 15, 2014 at 9:33
  • Is getting a list separately before using tar an option?
    – ek9
    Apr 15, 2014 at 9:36
  • Do you want only files or directories as well ? (tar -v is showing both)
    – Ouki
    Apr 15, 2014 at 9:38
  • 1
    What makes --verbose a not-so-good option? Did you consider --index-file=FILE
    – Johan
    Apr 15, 2014 at 12:30
  • 1
    I don't understand what the problem is. On my GNU tar 1.26, the only output of tar -cvf foo.tar * is the list of files. What is the "all output" that you want to avoid?
    – terdon
    Apr 15, 2014 at 14:00

3 Answers 3


You mention you don't like tar --list because it's slow. I'm guessing this is because it's a large tarball, and it has to re-scan the whole thing. If this is indeed the case, you can get better performance out of this by scanning as it's being created:

tar -c /input/directory | tee output.tar | tar -t > filelist.txt

This uses tee to split the resulting tarball, one going to a file, the other going to tar -t.

If you want to gzip the tarball:

tar -c /input/directory | tee >(gzip > output.tar.gz) | tar -t filelist.txt

We don't have the first tar do the gzip as it'll waste CPU cycles when the second tar has to decompress it again. Instead we only gzip the tarball as it's being written to disk.


You could append each file to the tar file:

for f in file ...; do 
    echo "$f"
    tar rf result.tar $f

This would put the error messages (stderr) in one file and file list (stdout) in one file:

$ tar -cvf archive.tar test nonexisting 1> stdout.txt 2> stderr.txt

$ cat stdout.txt

$ cat stderr.txt
tar: nonexisting: Funktion "stat" misslyckades: Filen eller katalogen finns inte
tar: Avslutar med felstatus på grund av tidigare fel

Using --index-file as suggested by Johan in the comment to my question would also work good:

tar --create \
    --verbose \
    --index-file=$fileList \
    --file $archiveFile \
    $filesystemToArchive \
    &>> $logFilename

From tar manpages:


send verbose output to FILE

You must log in to answer this question.

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