A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/xz-lossless-data-compression-tool-in-linux-with-examples/ below:

XZ (Lossless Data Compression) Tool in Linux with Examples

XZ (Lossless Data Compression) Tool in Linux with Examples

Last Updated : 23 Jul, 2025

xz is a general-purpose data compression and decompression command-line tool. It is similar to gzip and bzip2. It can be used to compress and decompress the files. The native file format of xz is .xz. But it can also support other various formats to compress or decompress files.xz gives us complete control over the compression and decompression of files. In Linux, xz tool is come by default with the system you don't need to install it. Now let's see how to use the xz tool to compress the files.

What is xz in Linux?

`xz` is a data compression tool in Linux. It uses the LZMA2 compression algorithm to achieve high compression ratios. It is commonly used for compressing files to save space and for packaging software distributions due to its efficiency and effectiveness. The `xz` command can able to compress, decompress, and test files providing the versatility of utility management for compressed data in various scenarios.

Why use xz?

The following are the some of the reasons and insights on the use of linux xz:

How to do Compressing of files using xz?
xz filename

xz -z filename

How to do Decompressing of files with xz?
xz -d filename

unxz filename

Creating compressed file without deleting an original file using xz
xz -k filename

Controlling the size of compression in xz

We can control the size of compressing the file using the xz .xz provides the options for compression level between 0 and 9 the default value of compression level is 6. Here the 0 is the fast but less compressed file, and we can use the --fast option for the 0 levels. And the 9 is slow more compress the file, and we can use the --best option for level 9.

xz -8 filename

Reducing Ram Usage

We can reduce the memory usage using the --memlimit-compress option provided by the xz. Now let's see how to use --memlimit-compress option. To use the --memlimit-compress option u mention percentage how many percent of system ram use is allocated to the xz with the --memlimit-compress like:

xz --memlimit-compress=20% filename

Progress Monitor While compressing and Decompressing:

To monitor the progress of current compressing or decompressing operation xz provide the verbose mode we can enable the verbose mode by using the -v options like.

xz -v filename

Here is example:

man xz

Difference between tar xz and zip

The following are the differences between tar xz and zip tools:

Feature tar xz zip Compression Algorithm It uses xz (LZMA2 algorithm) It uses deflate algorithm File Handling it combines multiple files into a single archive before compressing It compresses files individually within a single archive Compression Ratio it generally offers higher compression ratios Typically lower compression ratios compared to xz Compatibility Commonly used in Unix/Linux environments; requires additional tools on Windows It is widely supported across all major operating systems including Windows, macOS, and Linux File Extension It commonly results in .tar.xz files It results in .zip files Exmaples of XZ Command

The following are the examples of XZ Command:

1. Compress a File

xz file.txt

2. Decompress a File

xz -d file.txt.xz

3. compress the Maximum Compression

xz -9 file.txt

4. Keep Original file after Compression

The following is the command used to compress and keep the original file:

xz -k file.txt
Best Practices of XZ Command

The following are the best practices of XZ Command:

Use Cases of XZ Command

The following are the use cases of XZ Command:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4