bash: /bin/tar: Argument list too long when compressing many files with tar

Giancarlo Ventura Granados picture Giancarlo Ventura Granados · May 23, 2014 · Viewed 17.7k times · Source

I am trying compress files from an archive with the command

tar -czvf compress_file.tar.gz $(cat file_list.txt)

And I have an error

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

The files numbers is too long, how can I resolve this?

Answer

Mark Setchell picture Mark Setchell · May 23, 2014

Use the "-T" option to pass a file to tar that contains the filenames to tar up.

tar -cv -T file_list.txt -f tarball.tar