To compress a folder using the command line, you can use various tools depending on the compression format you prefer. Here are a few examples:
- ZIP Compression:
- Syntax:
zip -r your_archive.zip folder_to_compress
- Explanation:
zip
: Command for creating a ZIP archive.-r
: Recursive flag to include all files and subdirectories within the specified folder.your_archive.zip
: Name of the resulting ZIP file.folder_to_compress
: Path to the folder you want to compress.
zip -r myarchive.zip myfolder
- GZIP Compression (TAR + GZIP):
- Syntax:
tar -czvf your_archive.tar.gz folder_to_compress
- Explanation:
tar
: Command for creating a TAR archive.-c
: Create a new archive.-z
: Use GZIP compression.-v
: Verbose mode to display progress.-f
: Specify the name of the resulting archive.your_archive.tar.gz
: Name of the resulting TAR GZIP file.folder_to_compress
: Path to the folder you want to compress.
tar -czvf myarchive.tar.gz myfolder
- TAR Compression:
- Syntax:
tar -cvf your_archive.tar folder_to_compress
- Explanation:
tar
: Command for creating a TAR archive.-c
: Create a new archive.-v
: Verbose mode to display progress.-f
: Specify the name of the resulting archive.your_archive.tar
: Name of the resulting TAR file.folder_to_compress
: Path to the folder you want to compress.
tar -cvf myarchive.tar myfolder
- RAR Compression:
- Syntax:
rar a your_archive.rar folder_to_compress
- Explanation:
rar
: Command for creating a RAR archive.a
: Archive mode to create a new archive.your_archive.rar
: Name of the resulting RAR file.folder_to_compress
: Path to the folder you want to compress.
rar a myarchive.rar myfolder
- 7z Compression:
- Syntax:
7z a your_archive.7z folder_to_compress
- Explanation:
7z
: Command for creating a 7z archive.a
: Archive mode to create a new archive.your_archive.7z
: Name of the resulting 7z file.folder_to_compress
: Path to the folder you want to compress.
7z a myarchive.7z myfolder
Remember to replace your_archive
with the desired name for the resulting compressed file and folder_to_compress
with the actual path to the folder you want to compress.
To decompress or extract a compressed folder or file in the command line, you can use various commands depending on the compression format used. Here are the commands for different compression formats:
- ZIP Decompression:
- Syntax:
unzip your_archive.zip
- Explanation:
unzip
: Command for extracting ZIP archives.your_archive.zip
: Name of the ZIP file you want to extract.
unzip myarchive.zip
- GZIP Decompression (TAR + GZIP):
- Syntax:
tar -xzvf your_archive.tar.gz
- Explanation:
tar
: Command for manipulating TAR archives.-x
: Extract files from the archive.-z
: Use GZIP decompression.-v
: Verbose mode to display progress.-f
: Specify the name of the archive.your_archive.tar.gz
: Name of the TAR GZIP file you want to extract.
tar -xzvf myarchive.tar.gz
- TAR Decompression:
- Syntax:
tar -xvf your_archive.tar
- Explanation:
tar
: Command for manipulating TAR archives.-x
: Extract files from the archive.-v
: Verbose mode to display progress.-f
: Specify the name of the archive.your_archive.tar
: Name of the TAR file you want to extract.
tar -xvf myarchive.tar
- RAR Decompression:
- Syntax:
unrar x your_archive.rar
- Explanation:
unrar
: Command for extracting RAR archives.x
: Extract files from the archive.your_archive.rar
: Name of the RAR file you want to extract.
unrar x myarchive.rar
- 7z Decompression:
- Syntax:
7z x your_archive.7z
- Explanation:
7z
: Command for extracting 7z archives.x
: Extract files from the archive.your_archive.7z
: Name of the 7z file you want to extract.
7z x myarchive.7z
Remember to replace your_archive
with the actual name of the compressed file you want to extract. The extracted files will be placed in the current directory unless specified otherwise.