How to use the SSH tar command
The SSH tar (tape archive) command creates and extracts compressed archives. In particular, it’s essential for making full backups of your files and folders or restoring a website transferred from another host. Furthermore, tar works with gzip (.tar.gz) or bzip2 (.tar.bz2) compression – making it the standard tool for bundling and unpacking files on Linux servers via SSH.
Creating an archive
To create a compressed archive of specific files:
tar -czvf archiveToCreate.tar.gz file1 file2 file3This creates archiveToCreate.tar.gz containing the listed files. The archive name must come after -f. The flags mean:
c– create a new archivez– compress with gzip (usejfor bzip2)v– verbose, show files as they’re addedf– use the following filename for the archive
Creating an archive of a directory
To archive all files within a directory using a wildcard:
tar -czvf backup.tar.gz /path/to/directory/*To archive the entire directory including its structure, omit the asterisk:
tar -czvf backup.tar.gz /path/to/directory/Example—backup your WordPress files:
tar -czvf wordpress-backup.tar.gz public_html/Extracting an archive
To extract all files from an archive into the current directory:
tar -xzvf archiveToExtract.tar.gzThe only change from create is -c (create) replaced by -x (extract). The z tells tar the file is gzip-compressed. To extract to a specific directory, add -C /path/to/destination:
tar -xzvf archive.tar.gz -C /home/user/restore/Listing an archive
To list the contents of an archive without extracting it, use this SSH tar command:
tar -tzvf archive.tar.gz.
The -t option lists the files inside the archive, and the other flags work as before. This helps you confirm what’s in the archive or find a specific file before extracting.
Common use cases
Typical uses for SSH tar command on a Linux hosting account:
- Making full backups of website files before updates or migrations
- Restoring a website transferred from another host
- Compressing logs or old data to save disk space
- Bundling multiple files for download or transfer
For moving archives to another server, use scp or wget. For listing archive contents without extracting, use tar -tzvf archive.tar.gz.
Need more help?
Explore more SSH and hosting guides in our knowledgebase. JetHost web hosting includes SSH access for managing your server and creating backups directly.


