Wednesday, October 29, 2008

Create a Tar File of current Directory and Sub Directories


Create a tar file of current directory and all sub directories:


Just give the name of the directory to tar. For example, suppose you want to create a tar file for all the files (including all subdirectories) in the directory called myfiles. Give this command from the directory that contains myfiles:
Code:
tar cvf myfiles.tar myfiles

The find command is used to create a list of all the file names that end in .tex. The --files-from argument to tar is then used; this tells tar to only archive those files listed in /tmp/texfilenames.


To check the list of files in the tar file, you can use the t option. For example,

Code:
tar tf myfiles.tar | less 


Search for files and archive only select ones from a list in a file:


Code:
find myfiles -name "*.tex" > /tmp/texfilenames
tar cvf myfiles.tar --files-from /tmp/texfilenames

No comments: