linuxbashtar

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


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