How to use tar to compress a group of files in a .txt file

tar

I have a lot of filenames that listed in a .txt file called to_be_archived_files.txt, and its content is as:

~/Documents/dir1/a.html
~/Documents/dir1/b.html
~/Documents/dir1/c/1.html

How do I add all of them into a archive.tar.gz by tar?

I want something like:

tar czf archive.tar.gz -FROM-FILELIST=to_be_archived_files.zip

How can I achieve that?

Best Answer

Use the -T option:

 -T, --files-from FILE
       get names to extract or create from FILE

Note that it doesn't work with ~ as alias for home directory, you need to specify the folder explicitly.

Related Question