Create/Extract a tar file using contents of a file

If you want to create a tar that contains only files specified in a file you can use the -T option.

Example:

[[email protected] play]$ cat list.txt  
1.txt  
2.txt  
3.txt  
[[email protected] play]$ tar -cvzf files.tgz -T list.txt  
1.txt  
2.txt  
3.txt  
[[email protected] play]$ tar -tvzf files.tgz   
-rw-rw-r-- bcane/bcane 0 2011-07-13 16:48 1.txt  
-rw-rw-r-- bcane/bcane 0 2011-07-13 16:48 2.txt  
-rw-rw-r-- bcane/bcane 0 2011-07-13 16:48 3.txt

-T will work for both creation and extraction of tar files.

About Benjamin

Benjamin is a Infrastructure and Software Engineer. On this blog he writes about Linux, Docker, Programming as well as other Systems topics.

Learn more about Linux

If you liked this article, check out Benjamin's book: Red Hat Enterprise Linux Troubleshooting Guide. Where you can learn a lot more about troubleshooting Linux systems. This book is filled with tips and techniques he has learned over years of managing mission critical systems.

Related