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

Issue

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?

Solution

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

tar -czv -T file_list.txt -f tarball.tar.gz

Answered By – Mark Setchell

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published