Compression command in linux
There are mainly .zip, .gz, .bz2, .tar.gz and .tar.bz2 compression formats in Linux
1. .zip, .gz, .bz2 format
.zip format syntax:
- zip compressed file name source file #Compressed file (directories can also be compressed, but only the first directory will be compressed, and the contents in the directory will not be compressed)
- zip -r compressed file name source directory #compressed directory
- unzip compressed file name #unzip file
Compress the 11.txt file into: 11.zip file: zip 11.zip 11.txt

Compress the coding directory into: coding.zip file: zip -r coding.zip coding (As you can see from the picture below, all the contents in the directory will be compressed)

Compress the coding directory into: coding.zip file: zip coding.zip coding (it only compresses coding/, which does not contain the original content of the coding folder)

Decompress the coding.zip file (the coding.zip file obtained in the picture above), you can see that all the original first.c and other files are gone

.gz format syntax:
-
gzip source file #Compress to a compressed file in .gz format, the source file will disappear
-
gzip -c source file > compressed file #Compress to .gz format, keep the source file. For example: gzip-c cangls>cangls.gz
-
gzip -r directory #Compress all subfiles in the directory, but the directory cannot be compressed
-
gunzip compressed file name #unzip compressed file

.bz2 format syntax
- bzip2 source file #Compress to .bz2 format, do not retain the source file
- bzip2 -k source file #Keep the source file after compression
- Note: The bzip2 command cannot compress directories
- bzip2 -d compressed file #Decompress, -k retain compressed file
- bunzip2 compressed file #Decompress, -k retains the compressed file

2. .tar.gz, .tar.bz2 format
In response to the shortcoming that the .gz and .bz2 formats cannot compress directories, Linux can solve this problem by first packaging all the files in a directory through the tar command, and then compressing them into .gz or .bz2 formats.
Packaging command tar
- tar-cvf package file name source file
- Options: -C: Packaging -V: Display process -f: Specify the packaged file name
For example:

.tar.gz compression format In fact, the .tar.gz format is first packaged into .tar format and then compressed into .gz format
- tar-zcvf compressed package name # -z: compress to .tar.gz format (the source file will be retained), the absolute path can be added before the compressed package name
- tar-zxvf compressed package name # -x: decompress .tar.gz format (the original compressed file will be retained)
- tar-ztvf compressed package name # -t: Do not decompress the compressed package, directly view the contents of the compressed package

.tar.bz2 compression format
- tar -jcvf compressed package name.tar.bz2 source file
- tar -jxvf compressed package name.tar.bz2
- tar -jtvf #View the contents of the compressed package without decompressing the file

In Linux, .tar.gz and .tar.bz2 are the two most common compressed file formats. From the above practice, we can see that these two file formats can easily compress files. and directory, you can also view the contents contained in the compressed package, so these two formats need to be mastered proficiently. As for the .zip, .gz, and .bz2 formats, it is enough to understand them. No proficiency is required. When using them, just a little bit Impression, just find Du Niang.
The above is the detailed content of Compression command in linux. For more information, please follow other related articles on the PHP Chinese website!

Linux'scommandlinecanbemoresecurethanWindowsifmanagedcorrectly,butrequiresmoreuserknowledge.1)Linux'sopen-sourcenatureallowsforquicksecurityupdates.2)Misconfigurationcanleadtovulnerabilities.Windows'commandlineismorecontrolledbutlesscustomizable,with

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res

Wine 10.0 stable version release: Running Windows applications on Linux to a higher level Wine, this open source and free application, allows Linux users to run Windows software and games on Unix/Linux operating systems, ushering in the release of the 10.0 stable version! This version has been provided with source code and binary package downloads, and supports various distributions such as Linux, Windows and Mac. This edition embodies a year of hard work and over 8,600 improvements, bringing many exciting improvements. Key highlights include: Enhanced support for Bluetooth devices. Improve support for HID input devices. Optimized performance of 32-bit and 64-bit applications.

This tutorial guides you through installing SQL Server 2022 on RHEL 8.x or 9.x, connecting via the sqlcmd command-line tool, database creation, and basic querying. Prerequisites Before beginning, ensure: A supported RHEL version (RHEL 8 or 9). Sudo

Mozilla Thunderbird 135: Powerful cross-platform mail client Mozilla Thunderbird is a free, open source, cross-platform email, calendar, news, chat and contact management client designed to efficiently handle multiple email accounts and news sources. On February 5, 2025, Mozilla released the Thunderbird 135 version, introducing a number of new features, performance improvements and security fixes. Thunderbird 135 main features: XZ Packaging for Linux Binaries: Smaller files, faster unpacking, and better integration with modern distributions. Cookie storage support: when creating space


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
