Overview
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 following describes the various types of compressed files and their extensions, which you can decompress using your computer's software. You can also upload the compressed file to your web server and decompress it there. This requires you to log into the server via SSH and run a command.
Make sure to change all references of username in the following examples to your Shell user.
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.
.zip (Zip archive)
ZIP files end with the extension .zip. Run the following to decompress:
[server]$ unzip filename.zip Archive: filename.zip inflating: list inflating: of inflating: files inflating: being inflating: uncompressed inflating: from inflating: the inflating: zip inflating: archive
All files are extracted in the directory where you ran the command. View the following site for more information:
.gz (Gzip)
GZIP files end with the extension .gz. The gunzip command unzips a file so you can open it normally. This command is particularly important for DreamHost users. In your website's home directory is a log folder which stores your error.log and access.log files. View the following article for more information:
Older logs end with .gz. You can use the following command to unzip a log file and view its contents:
[server]$ gunzip error.log.2020-04-11.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 following site for more information:
.tar
TAR files end with the extension .tar. By default, .tar files are not compressed, they just archive several files into a single file. If a .tar file was 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. Run the following commands to open a .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 following site 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 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. View the following site for more information:
.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 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. View the following site for more information: