Compress and Un-compress
Zip
The -r option is used to recursively zip files. This option will compress all the files present within a folder. An example of such command is as shown below:
Exclude Files in a Zip (Here ExampleFile.txt will not be added to the sampleZipFile.zip.)
Zip with Password
Unzip to a Different Directory
Use Linux Unzip with Multiple Zip Files
Suppress Output When Using Unzip in Linux (In case you want to suppress these messages, then you can use the -q option. The command would be as shown below:)
Exclude Files Using Unzip in Linux
Using Unzip in Linux with Password Protected Files
Overriding Zip Files
[y]es, [n]o, [A]ll, [N]one, [r]ename
You can override these files by using the -o options
Using Linux Unzip Without Overwriting Files
How to List the Content of a Zip in Linux
Tar
Options
Options:
-c : Creates Archive
-x : Extract the archive
-f : creates archive with given filename
-t : displays or lists files in archived file
-u : archives and adds to an existing archive file
-v : Displays Verbose Information
-A : Concatenates the archive files
-z : zip, tells tar command that creates tar file using gzip
-j : filter archive tar file using tbzip
-W : Verify a archive file
-r : update or add file or directory in already existed .tar file
This command creates a tar file called file.tar which is the Archive of all .c files in current directory.
gzip compression on the tar Archive, using option -z
Extracting files from Archive using option -xvf : This command extracts files from Archives.
Extracting a gzip tar Archive *.tar.gz using option -xvzf
Creating compressed tar archive file in Linux using option -j : This command compresses and creates archive file less than the size of the gzip. Both compress and decompress takes more time then gzip.
Untar single tar file or specified directory in Linux
Untar multiple .tar, .tar.gz, .tar.tbz file in Linux : This command will extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file. For example the above command will extract “fileA” “fileB” from the archive files.
or
or
Check size of existing tar, tar.gz, tar.tbz file in Linux : The above command will display the size of archive file in Kilobytes(KB).
Update existing tar file in Linux
list the contents and specify the tarfile using option -tf
Applying pipe to through ‘grep command’ to find what we are looking for
Viewing the Archive using option -tvf
To search for an image in .png format
Zst
The extention .zst means that the archive is compressed by zstd.
Simple
Decompress
If you want to compress a directory, or combine multiple files into a single archive, you’ll need to use tar to create an archive and then compress it with zstd. You’ll need to add the --zstd option, along with any other flags you choose.
Alternatively, we could use the a option with the tar command, which will choose the correct compression method based on the file extension (zst in this case) specified.
Use the following tar command to open a Zstandard tarball.
Alternatively, the a option can save us a few keystrokes again.
Gunzip Gzip
To Decompress A File Using The "gunzip" Command:
Force A File To Decompress:
To keep both the compressed and decompressed file:
To display compressed output:
Decompressing Lots Of Files Recursively:
Compression Size Time Elapsed Command
gzip 955 MB 1:45 tar cfz files.tar.gz files/
xz 856 MB 16:06 tar cfJ files.tar.xz files/
bzip2 943 MB 5:36 tar cfj files.tar.bz2 files/
7zip 851 MB 10:59 7z a files.7z files/
zip 956 MB 1:41 zip -r files.zip files/
rar 877 MB 6:37 rar a files.rar files/*
zstd 934 MB 0:43 tar --zstd -cf files.tar.zst files/