How to Compress and Decompress Files CLI Command
This guide outlines how to compress and decompress files and directories into various formats, such as .zip, .tar, .gz, .bz2, and more. While these operations can be performed using a graphical user interface (GUI) with tools like cPanel's File Manager, this document primarily focuses on command-line operations, which can be executed via SSH. This is particularly useful for those who prefer or require scriptable or command-line interactions. However, if you prefer using a GUI for compressing or decompressing files, cPanel's File Manager offers a user-friendly web-based interface for these tasks.
- Compressing and Decompressing via SSH
- .zip Files
- .bz2 Files
- .gz Files
- .tar Files
- .tar.bz2 Files
- .tar.gz Files
- Learning More About Commands
- Summary
Compressing and Decompressing via SSH
Below are the commands for various file formats, allowing you to compress or decompress files and directories.
Working with .zip Files
zip file.ext
- To Extract:
unzip archive.zip
- To Compress:
Working with .bz2 Files
bzip2 file.ext
- To Extract:
bunzip2 archive.bz2
- To Compress:
Working with .gz Files
- To Extract:
gzip -d archive.gz
- To Compress:
gzip file.ext
Working with .tar Files
- To Extract:
tar -xvf archive.tar
- To Compress:
tar -cvf archive.tar file1.ext file2.ext directory/
Working with .tar.bz2 Files
- To Extract:
tar -xvjf archive.tar.bz2
- To Compress:
tar -cvjf file.tar.bz2 file1.ext file2.ext directory
Working with .tar.gz Files
- To Extract:
tar -xvzf archive.tar.gz
- To Compress:
tar -cvzf file.tar.gz file1.ext file2.ext directory/
Learning More About Commands
The commands listed above represent the most basic usage. Many additional options can enhance or modify the behavior of these commands. For further learning, the man command can be utilized to access the manual pages of each command, providing detailed information on usage, options, and examples.
To learn more about a specific command:
man < command >
Replace "< command >" with the command you wish to learn more about, such as "tar" or "gzip." Please note, while this guide aims to provide useful information on file compression and decompression, Bluehost does not offer technical support for these command-line operations.
Summary
This guide provides comprehensive instructions on how to compress and decompress files using the command-line interface (CLI), covering file formats such as .zip, .tar, .gz, and .bz2, primarily via SSH. It details commands for extracting files like unzip for .zip files and tar -xvf for .tar files, and commands for compressing, including zip and tar -cvf. For those looking to deepen their understanding, the man instruction is invaluable. This method is particularly beneficial for users who require the scriptability and flexibility of CLI operations over graphical interfaces like cPanel's File Manager.
If you need further assistance, feel free to contact us via Chat or Phone:
- Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
- Phone Support -
- US: 888-401-4678
- International: +1 801-765-9400
You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.