Using tar in Ubuntu
Recommended Ubuntu book
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:
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:
tar czf directory_name.tar.gz directory_name/
where “c” means create, “z” for gzip compression and “f” for file.
You can also do:
tar cjf directory_name.tar.bz2 directory_name/
for bzip compression or just:
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:
tar xf directory_name.tar
tar xzf directory_name.tar.gz
tar xjf directory_name.tar.bz2
That’s it.