How to: tar a file, gzip a file, untar a file

I thought I’d share incase anybody else runs into the problem and needs to tar or gzip a file on their server.

How to tar and then how to gzip (compress) a file in SSH
When you are logged into SSH this command line should tar and then gzip your folder into a .tar.gz file. This will gzip your file into the current directory:
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.gz foldername

How to untar and how to ungzip (or unzip) a file in SSH:
This will 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:
gunzip -dc whatever.tar.gz | tar xvf -

Thank you, and good night.

5 Responses to “How to: tar a file, gzip a file, untar a file”


  1. 1 Athan

    thanks. this helped!

  2. 2 Smoother

    Thanks for stopping by and I’m glad this helped you out Athan.

  3. 3 Moataz Almadawy

    thanks man great pos

  4. 4 TA

    Thanks a lot, this is near the top when you google “how to tar” and so will help a lot of people…

  5. 5 Nick

    Hi,

    How to untar? It gives me error

    tar: Multiple archive files require `-M’ option
    Try `tar –help’ or `tar –usage’ for more information.
    [root@host ~]# tar -czf /home/music/lyrics_songs.sql.gz
    tar: Cowardly refusing to create an empty archive
    Try `tar –help’ or `tar –usage’ for more information.
    [root@host ~]#
    [root@host ~]# gunzip -dc /home/music/lyrics_songs.sql.gz | tar xvf -
    tar: This does not look like a tar archive
    tar: Skipping to next header
    tar: Archive contains obsolescent base-64 headers

    Thanks,
    SmartWebHosts.Com

Leave a Reply