A tar.xz file extension shows that the file is a tar archive file compressed using the XZ compression tool. In this guide, we will cover various examples of how to list contests of a tar.xz file, and extract all or specific files or directories in a tar.xz file. We will also cover how to download and extract an archive file with a single command using the tar utility.
This guide shows various examples of how to extract tar files compressed using xz, a general-purpose data compression tool.
Table of Contents
How to List tar.xz Files in Linux
To list the contents of a file with tar.xz extension, run the tar command with the -t
or --list
and -f
flags, which instruct the tar command to list the contents of an archive and specify the file name respectively, as follows:
$ tar -tf trilium-linux-x64-0.58.7.tar.xz
You can enable verbose output or long listing format using the -v
or --verbose
option. In this case, the tar command output will show the list of files or directories together with their permissions, size, date of last modification, etc.
$ tar -tvf trilium-linux-x64-0.58.7.tar.xz
How to Extract tar.xz Files in Linux
To extract all files in a tar.xz archive file, run the tar command with the -x
or --extract
or --get
flag as follows, which will run in non-verbose mode.
$ tar -xf trilium-linux-x64-0.58.7.tar.xz
You can also enable verbose mode as follows, which will allow for viewing the list of files as they are extracted:
$ tar -xvf trilium-linux-x64-0.58.7.tar.xz
Extract tar.xz Files to Specific Directory
To save the extracted files to a specific directory, use the -c
flag.
$ tar -xvf trilium-linux-x64-0.58.7.tar.xz -C /tmp/
How to Extract Specific Files from tar.xz in Linux
You can also extract specific files from the tar.xz archive file. Simply specify the space-separated file names as arguments after the name of the archive file in the following format.
You can list files in the archive file to view the filename(s) you would like to extract as shown before.
$ tar -xf trilium-linux-x64-0.58.7.tar.xz trilium-linux-x64/trilium-safe-mode.sh trilium-linux-x64/trilium-portable.sh
Note that you have to specify the absolute path of a file within the archive file, for example, trilium-linux-x64/trilium-portable.sh.
Extract Specific File Extension in tar.xz File
To extract all files with a specific extension, for example, .sh
or .sql
you can use tar’s --wildcards
file matching flag as follows:
$ tar -xf trilium-linux-x64-0.58.7.tar.xz --wildcards '*.sh' '*.sql'
Extract Directories in tar.xz File
To extract directories/folders from the archive file, simply specify their names in the same fashion, as shown.
$ tar -xf trilium-linux-x64-0.58.7.tar.xz trilium-linux-x64
How to Extract tar.xz Archive File From Stdin
It is also possible to download an archive file and extract it straightaway using a single command. The following examples show how to download an archive file using the curl command or wget commands and extract it in one go.
You have to specify the decompression option because a tar.xz archive file is filtered through XZ compression, you need to specify the -J
or --xz
option as the decompression option as shown.
$ curl https://github.com/zadam/trilium/releases/download/v0.58.7/trilium-linux-x64-0.58.7.tar.xz | tar -xJ OR $ wget https://github.com/zadam/trilium/releases/download/v0.58.7/trilium-linux-x64-0.58.7.tar.xz | tar -xJ
For more information, read the tar man page by running:
$ man tar
That’s all we had for you in this guide. If you have any queries, let us know via the feedback form below.