A simple guide for those who are as helpless on the Linux command line. When managing websites, you’ll often need to compact, move and extract a large number of files, here’s how to do it on your Linux box.
First SSH into your web server and move to the directory of the files you wish to tar up, since tarring an absolute path will save the folder structure as well which is bad (ie: /home/yoursite/public_html/backupthis/ will save the folders home -> yoursite -> public_html -> backupthis). You can get to the folder you need to by typing:
Creating a Tar
Now that we’re at the directory we want to tar, or the sub-directory, you can do one of two commands depending on what you need.
If you want to save every file / folder in your current location into a file called backup.tar.
tar -cvf backup.tar *
If you want to save a tar named backup.tar with the folder “somefolder” and its contents.
tar -cvf backup.tar somefolder/
You can test/view your tars with the following command:
tar -tvf backup.tar
Extracting the Tar
When you need to extract that tar, the following command will be suffice:
tar -xvf backup.tar