tar your files

In windows, you just right click on a folder and say add it to zip, the folder and its contents including the sub-folders are compressed and stored in a zip file or rar file. No such luxury in Linux. Or even if it is there I do not know about it.

But you can easily use tar command to create a single archive of your folders. Do not be overwhelmed by the large number of options and flags given in the man page. Let us just see the basic usage here.

To create a tar file

You can use the options -c for create,-v  for verbose and  -f for tar file name.

tar -cvf myfile.tar mydirpath

Lo, your file myfile.tar is created.

But keep in mind that, tar is not a compressed file. To compress, you can use gzip utility on the tar file. Or you can even use option -j or --bzip2

tar -cjvf myfile.bz mydirpath


To extract a tar file

There is no untar command in Linux. You should use -x for extraction.

tar -xvf myfile.tar

Extracts the contents of myfile.tar to the current folder.

tar -xvf myfile.tar -C anotherdir

Extracts the contents to the directory specified

To extract the contents of zipped tar file, you can use -j option

tar -xjvf myfile.tar

Unzips the file and extracts and stores them in current folder.

Comments

Popular Posts