Linux / Unix tar command 1 comment


Examples

Note: A “.tar” file is not a compressed files, it is a collection of files within a single file uncompressed. If the file is a .tar.gz (“tarball”) or “.tgz” file it is a collection of files that is compressed. If you are looking to compress a file you would create the tar file then gzip the file.

Creating a tar file:

tar -cvwf file.tar myfile.txt

In the above example the system would create a tar named file.tar in the directory you currently are in. Wildcards could also be used in this command, for example: tar -cvwf file.tar *.txt would compress all txt files in the current directory.

tar -cvwf home.tar home/

In the above example command the system would create a tar file named home.tar in the directory you currently are in of the home directory.

Extracting the files from a tar file:

tar -xvwf myfile.tar

In the above example command the system would uncompress (untar) the myfile.tar file in the current directory.

tar -xvwzf myfile.tar.gz

In the above example command the system would uncompress (untar) the myfile.tar.gz file in the current directory.

Note: There is no “untar” linux / unix command.

Creating a tarred file that is compressed with bzip

tar -cjvf test.tbz home/

Adding the j option to the tar command enables tar to compress files and directories using bzip. In the above example the home directory and all its subdirectories are added to the compressed test.tbz file.

Reference : http://www.computerhope.com/unix/utar.htm

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools


One thought on “Linux / Unix tar command