Overview
This article explains how to decompress different file formats via SSH, either on your home computer or a DreamHost server.
Why is this necessary?
Websites often allow you to download a single compressed file that contains many other files. This makes it easier and faster to download through your browser since the file is smaller than the folder containing all the files.
The compressed file must then be decompressed before you can access and use the files within it.
Prerequisites
This article assumes you have Created a Shell user and are able to log into your server via SSH.
You can also run these commands on your home computer within a shell terminal.
Flags used to decompress files
The commands unzip and tar are shown below. Each has several flags you can (or must) use to decompress the file.
zip flags
View the zip Linux man page for more information.
tar flags
- f = Informs the tar command that the next parameter is the file name of the archive.
- j = Filters the archive through bzip2.
- v = Verbose (optional). Displays the files as they are decompressed.
- x = Extracts files from an archive.
- z = Filters the archive through gzip.
- C = Sends the output to a specific directory.
Decompressing files
.zip (Zip archive)
ZIP files end with the extension .zip. Run the unzip command to decompress:
[server]$ unzip filename.zip
All files are extracted in the directory where the command is run. View the zip man page for more information:
.gz (Gzip)
GZIP files end with the extension .gz. Run the gunzip command to decompress.
This command is particularly important for DreamHost users. In your website's home directory is a log folder that stores your error.log and access.log files. Older logs end with .gz and can be decompressed with the following command:
[server]$ gunzip error.log.2024-04-02.gz
There is no output when you decompress the file. Run ls -la to view the directory you just ran the command in. You'll see the file no longer ends with .gz, and you can now open it in any normal text editor to view its contents. View the gzip man page for more information:
.tar
TAR files end with the extension .tar. By default, .tar files are not compressed; they archive several files into a single file. If a .tar file were compressed, it would end with .tar.gz or .tar.bz2. However, you can still open a .tar file in a similar way as a compressed .tar file.
Extract in the current directory
[server]$ tar xvf filename.tar
The contents are extracted into the current directory.
Extract in a different directory
[server]$ tar xvf filename.tar -C /home/username/
The contents are extracted into the /home/username directory. View the tar man page for more information:
.tar.gz
Gzipped TAR files end with the extension .tar.gz. Run the following commands to decompress a file:
Extract in the current directory
[server]$ tar xvzf filename.tar.gz
This creates a new folder in your directory that is named the same as the file.
Extract in a different directory
[server]$ tar -zxvf backup2.tar.gz -C /home/username/
This extracts the files into a folder in your /home/username/ directory.
.tar.bz2
Bzipped2 files end with the extension .tar.bz2. Run the following commands to decompress a file:
Extract in the current directory
[server]$ tar xvjf filename.bz2
This creates a new folder in your directory that is named the same as the file.
Extract in a different directory
[server]$ tar xvjf filename.bz2 -C /home/username/
This extracts the files into a folder in your /home/username/ directory.