If you’re running a Linux based server, here a step by step guide on how to tar a file and then how to gzip (compress) that file using a simple SSH command.
When you are logged into your server through SSH, you can use this command line to tar and then gzip your folder into a tarball file. This will compress your file into the current directory
- tar -czf whatever.tar foldername
(another method would be…)- tar -czf whatever.tar.gz foldername
If you’d like to tar your file and have it put in another location use this:
- tar -czf /directory/directory/whatever.tar foldername
Now that you have a tar file, here’s how to untar / ungzip (or unzip, uncompress) a file in SSH. Using this command you’ll untar and uncompress your file, then it will place that folder in the directory you are currently in restoring your old folder and file structure.
- tar -xf whatever.tar
(another method would be…)- gunzip -dc whatever.tar.gz | tar xvf -
Here are a list of tar options, and their significance.
-c = create
-f = read to/from the named file (instead of the device /tape)
-t = list contents of .tar file
-r = append to a .tar file
-v = verbose (tells you everything its doing)
-x = extract contents of .tar file
-z = compress files
Want to learn more SSH commands? I recommend the book Linux in a Nutshell
If you’re a server admin, another thing you might be interested in is how to clear the qmail queue.
Very helpful, thanks!
Made things so much easier. Just for one problem. I connected to one linux server via putty then to another via ssh. Trying to transfer files from one to the other. After compressing i am trying to transfer using the command
get filename.tar.gz
but am getting the response ‘-bash: get: command not found’
What could be the reason? Is this correct way to download from one server to another?
Try using wget instead of get.
This is probably because the GET command is not available because libwww is not installed on the server. You can search Google for “GET: command not found” but depending on the linux version you’re using, you might be able to run this command to install it, don’t forget the dashes.
apt-get install libwww-perl
or maybe this page will do the trick. http://webhostingneeds.com/GET:_command_not_found Good luck!
Hi thankx,
I did, however, find out that after connecting to the first server using putty i was supposed to connect to the other using ftp rather than ssh. When connected using ftp the get command worked.
ref: http://www.gontztechnologyservices.com/tips-and-instructions/linux-a-unix/using-ssh-to-ftp–sftp-from-one-remote-server-to-another.html
Thanks anyhow
This is great. Thanks. If I tar only a particular folder and then extract it to restore, it will not delete any files – only write over and add files within that directory – correct?
You’re correct. If you have an existing folder, and you untar an archive with different files, it will add the new files to the existing folder and leave existing files there. If there’s a file with the same name it will prompt if you want to overwrite the existing file.
Also doing this in reverse… you can add files to an existing tar file. Just use the option “–append” (or “-r“) and it will add new files to an existing tar archive (instead of overwriting the existing tar)
Worked perfectly! Thanks for the reply!
Got error Message when i tried to use tar -czvf
tar: z unknown function modifierIm using Solaris 10 btw and had to use tar -cvf
Good day!
Very Helpful. Saved my Bacon. Thanks.
Great summary, thanks! Very useful.