Using tar (Ubuntu)

Tar is pretty common command for archiving the files in Linux. It is pretty much the same across the distributions. You can type in the commands listed below in the Ubuntu terminal window.

Of course you can do:
root@penreturns:~$ man tar



and see all the flags and how to use, but hopefully this post will save you the effort.

To create an archive I usually do:
root@penreturns:~$ tar czf directory_name.tar.gz directory_name/

where “c” means create, “z” for gzip compression and “f” for file.

You can also do:
root@penreturns:~$ tar cjf directory_name.tar.bz2 directory_name/

for bzip compression or just:
root@penreturns:~$ tar cf directory_name.tar directory_name/

for a regular .tar

Basically, we specify the command with flags, type a file name that we want to create and pick a directory or file that we want to add to archive. These commands create an archive leaving the directory untouched.

Similarly, we extract these types of files using the “x” flag like this:
root@penreturns:~$ tar xf directory_name.tar
root@penreturns:~$ tar xzf directory_name.tar.gz
root@penreturns:~$ tar xjf directory_name.tar.bz2
Enjoy.

*copy code without root@penreturns:~$ 

Reply to this post

Post a Comment