XZ Compression Tutorial

29/12/2020
Many built-in command-line compression tools are available in Linux operating system. XZ is one of the popular data compression tools that works like any other standard compression tools, such as gzip, bzip2 etc. XZ command compresses and decompresses the file which is mentioned in the command with XZ. If any file name is not mentioned in the XZ command then the command reads data from standard input and after processing the data, write the data in standard output. XZ can compress or decompress one or more files at a time. Normally it removes the original file after compression and removes decompressed file after decompression. You can keep both compressed and uncompressed files by using some options. How you can use XZ command for compressing and decompressing file is shown in this tutorial.

Run the following command to find out the options of XZ command.

$ xz –help

Select some files that you want to test xz command. Here, the files of myDir folder are used for compressing and decompressing with xz command. Run ls -l command to show the list of files with detail information.

$ ls -l

Compress single file

You can compress any simple file by giving the file name with xz command. After compression, xz command deletes the original file. Here, b1.sh file is compressed and created the compressed file named b1.sh.xz.

$ xz b1.sh
$ ls -l

Compress multiple files

You can compress multiple files using xz command by separating each file with space. Here, two compressed files, loop2.sh.xz and myfile.txt.xz are created after deleting loop2.sh and myfile.txt.

$ xz loop2.sh myfile.txt
$ ls -l

Compress file by keeping original file

If you want to keep original file with compress file then run xz command with –k option. Here, comment2.sh.xz file is created without removing comment3.sh file.

$ xz -k comment3.sh
$ ls -l

Decompress file

Like compression, when you decompress any file with xz command then it delete decompressed file after

decompression.  Here, b1.sh file is created after decompressing b1.sh.xz file. –d option is used with xz command to decompress any compressed file.

$ xz -d b1.sh.xz
$ ls -l

Decompress file by keeping compressed file

You have to use –k option with unxz command to keep the decompressed file with original file after decompression. After running the following command, loop2.sh.xz file will not be removed.

$ unxz -k loop2.sh.xz
$ ls -l

Compress multiple file in a single file

If you want to create single compression file for multiple files then you need to use –c option. The following command will create new.xz compressed file after compressing b1.sh and FirstJava.class files.

$ xz -c b1.sh FirstJava.class > new.xz
$ ls -l

Retrieve information of compressed file

You can retrieve information of any compressed file by using –l option. Here, new.xz file is created by compressing two files. The following information shows that the original size of both files is 604 bytes and after compression the size is 548 bytes.  You can decompress this file by using previous decompression options.

$ xz -l new.xz

One of the major limitation of xz compression tool is that it can compress file only. You can’t compress any folder by using xz. This tool can’t also be used for creating password protected compressed file. There are other tools on Linux to create password protected compressed file. One of them is rar package. You can easily install trial version of rar package on Linux to create and open archive files. You can read the tutorial on rar package from the following link.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Các cách sử dụng proxy để bảo vệ máy tính của bạn khỏi các cuộc tấn công mạng.

Khi sử dụng proxy để lướt web, bạn có thể trải nghiệm nhiều lợi ích hữu ích như bảo vệ thông...
27/02/2023

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game

Trong thế giới game trực tuyến, việc có kết nối internet ổn định và bảo mật là yếu tố quan...
22/06/2023

How to Use CentOS Unzip

Zip is a file compression utility. It is the default file compression utility on Windows and widely used in Windows operating...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Huớng dẫn dùng proxy cho ios, iphone 2023
23/09/2023

Cách gắn set proxy cho điện thoại android, oppo, giả lập android, Ldplayer Bằng Proxydroid
20/09/2023

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game
22/06/2023

Mua Proxy Mỹ, Us Nuôi Tài Khoản Etsy, eBay Tìm Hiểu Về Mua Proxy Mỹ tại Onet.com.vn
22/06/2023

Mua Proxy Game – Giải pháp tuyệt vời cho việc chơi game trên mạng mà không bị giới hạn về vị trí địa lý
03/06/2023