The most well-known archive/compression tool in Linux
In many cases, sending or receiving large files and images over the Internet is a headache. The compression and decompression tools can solve this problem. Next, let's quickly browse some open-source tools in Linux that make our work easier.
Tar
Tar is derived from 'tape archiver, which is initially used to archive and store files on tapes. Tar is a GNU software that can compress a group of files (archive), extract them, and perform operations on existing archive files. It is useful in storage, backup, and file transfer. When creating an archive file, Tar can keep the original file and directory structure unchanged. The suffix of an object archived through Tar is '.tar '.
The basic usage is as follows:
A) create an archive (c/-- create)
tar --create --verbose --file=archive.tar file1 file2 file3
Or
tar cvf archive.tar file1 file2 file3
Create an archive
B) list the content of an archive object (t/-- list)
tar --list archive.tar
List objects contained in an archive
C) extract archive (x/-- extract)
tar xvf archive.tar
Tar xvf archive.tar -- wildcards '*. c'
-Extract files with the suffix *. c from the archive.
Extract files
Extract only required files
D) update the archive file (u/-- update)
Tar uvf archive.tar newfile. c
-If the archived newfile. c is newer than the previously archived newfile. c, add the updated newfile. c to the archive.
Update an archive
E) delete an object from the archive (-- delete)
tar --delete-f archive.tar file1.c
-Delete the file 'file1. c' from the compressed package 'archive.tar'
Delete an object
For more details, refer to the tar homepage.
Gzip/Gunzip
Gzip is GNU zip. It is a widely used compressed application in the Linux operating system. The suffix of the compressed file is '*. gz '.
The basic usage is as follows:
A) compressed file
gzip file(s)
Each file is compressed separately.
Compressed file
After compression is complete, it will delete the original file. We can use-c
To retain the original file.
gzip -c file > file.gz
Retain the original file after compression
We can also compress a group of files into a single file.
cat file1 file2 file3 | gzip > archieve.gz
Compressing a group of Files
B) Check the compression ratio
You can use the '-l' option to check the compression ratio of the compressed file.
gzip -l archieve.gz
Check compression rate
C) decompress the file
Gunzip is used to extract files. Here, the original (Compressed) files are also deleted after being decompressed. Use-c
To retain the original file.
gunzip -c archieve.gz
Decompress the file
Gzip + '-d' option and gunzip have the same effect on compressed files.
For more details, see the gzip homepage.
Bzip2/Bunzip2
Like gzip, Bzip2 is also a compression tool. Compared with other traditional tools, Bzip2 can compress files to a smaller size, but its disadvantage is that it is slower than gzip.
The basic usage is as follows:
A) compressed file
In general, Bzip2 does not need any options for compression, so it will pass the compressed file as its parameter. Each file is compressed separately, and the compressed file is suffixed with 'bz2.
bzip2 file1 file2 file3
File compression
You can use the '-k' option to retain the original file after compression or decompression.
Retain the original file after compression
B) decompress the package
The '-d' option is used for decompression.
Use the-d option to decompress the file
You can also use bunzip2 for decompression.
bunzip2 filename
Decompress the file
Bunzip2 can decompress files with the suffix bz2, bz, tbz2, and tbz. After the files with tbz2 and tbz are compressed, the suffix will be changed to '.tar '.
bzip2 -dc
-Decompress the file to the standard output.
7-zip
7-zip is another open source compression software. It adopts the new compression format 7z and supports high compression ratio. Therefore, it is considered to be a better software than the previously mentioned compression tool. In Linux, you can use the p7zip package, which contains three binary files: 7z, 7za, and 7zr, you can refer to p7zip wiki to learn about the differences between the three binary files. In this article, we will use 7zr to explain 7-zip usage. The archive file is suffixed with '.7z.
How to install 7zip in Linux
The basic usage is as follows:
A) create an archive
7zr a archive-name.7z file-name(s)/ directory-name(s)
Create an archive file
B) List Archived Files
7zr l archive-name.7z
List objects contained in an archive
C) extract archive files
7zr e archive-name.7z
Extract Archive
D) Update the archive file
7zr u archive-name.7znew-file
Update an archive file
E) delete an object from an archive object
7zr d archive-name.7z file-to-be-deleted
Delete an object
Confirm File Deletion
Decompress RAR and 7Z files in Ubuntu 12.10
This article permanently updates the link address: