How to extract file in linux

How to extract tar.xz files in Linux and unzip all files

H ow do I extract tar.xz files in Linux? Can you tell me command to unzip linux-5.6.13.tar.xz file? How can I uncompressing (or decompressing) all files in the current directory?

The tar command and xz command provides support for extracting and uncompressing tar.xz files and .txz archives under Linux operating systems.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements tar and xz commands on Linux
Est. reading time 6 minutes

How do I extract tar.xz files in Linux?

  1. Install xz using the dnf install xz on a CentOS/RHEL/Fedora Linux.
  2. Debian/Ubuntu Linux users try apt install xz-utils command.
  3. Extract tar.xz using the tar -xf backup.tar.xz command
  4. To decompress filename.tar.xz file run: xz -d -v filename.tar.xz

Installation

XZ is a set of open-source software for lossless data compressors, including LZMA and xz formats. These formats are popular among open source developers and projects due to higher compression rates than alternatives tools like gzip and bzip2. The tar command works if xz installed on the system. Hence, we must install it.

Debin/Ubuntu Linux install xz

Use the apt command/apt-get command:
$ sudo apt install xz-utils
Sample outputs:

CentOS/RHEL/Fedora Linux install xz

Open the terminal app and then run NA command/dnf command as follows:
$ sudo dnf install xz
## On an older version of CentOS/RHEL try yum ##
$ sudo yum install xz
From my CentOS 6.x box:

Installing xz on OpenSUSE/SUSE Enterprise Linux

We can use the zypper command to install xz:
$ sudo zypper install xz

OpenSUSE installing xz package for extraction purposes

Examples

Now we install xz. We can now directly use the tar command as follows for extracting a file named linux-5.6.13.tar.xz:
$ tar -xf linux-5.6.13.tar.xz
$ tar -xvf linux-5.6.13.tar.xz
$ tar -Jxvf linux-5.6.13.tar.xz
## extract tar.xz files aka .txz file ##
$ tar —xz -xf archive.txz

Extracting specific files from a tar.xz file

We extract a given file names from a backup.tar.xz file by using the following syntax:
$ tar -xf backup.tar.xz resume.pdf
$ tar -xf backup.tar.xz babys-3rd-cake-day.jpg sales.txt
Sometimes we don’t know file names in advance. Hence, we list the contents of an archive by passing the -t as follows and then unzip tar.xz files:
$ tar -tvf backup.tar.xz
## filter out tar listing option using the grep command/egrep command ##
$ tar -tvf backup.tar.xz | grep file1
$ tar -tvf backup.tar.xz | egrep ‘ file.txt | data.doc | cake.jpg ‘

Want to extract all Perl or Python source code files? Try the following option:
$ tar —wildcards ‘*.py’ -xvf webroot.tar.xz
$ tar —wildcards ‘*.pl’ -xvf centos-7-sysadmin-scripts.txz

Understanding tar command options

  • -x : Extract/get/unzip files from an archive.
  • -f archive.tar.xz : Use this archive file or device archive for extracting files
  • -J OR —xz : Filter the archive through xz command. Hence, we install xz using package manager.
  • -v : Verbose. Show progress.
  • -t : List file stored inside .tar.xz/.xz archive.
  • —wildcards : By default, wildcards don’t work as they treated or processed to by your current shell. Therefore, to extract files, use the —wildcards options. For example, extract all .webp images I would pass —wildcards ‘*.webp’ option to the tar.

How to extract .xz files using the xz command

So far, we learned to use tar for extracting. But, we can use xz command directly for as compressor and decompressor too. Tar internally calls xz itself or using API provided by libs. Let us see some tips and tricks for xz command.

Decompress .tar.xz file

$ xz —decompress filename.tar.xz
$ xz -v -d archives.tar.xz
Decompress file named mysql.sql.xz and replaced by mysql.sql:
$ xz -v -d mysql.sql.xz

Compress tarball as .tar.xz file

Compress a file named mysql.sql and replace it by mysql.sql.xz for saving disk space:
$ xz mysql.sql
The syntax is as follows for compressing per-existing tarball:
$ xz -v -z filename.tar
Alternatively, use the tar command for convenience purposes
$ tar -cv J f file1 file2
$ tar -cv J f /path/to/dir1 ./dir2
$ sudo tar -cv J f /efs/backups/14-05-2020/production-webroot.tar.xz /var/www/
$ sudo tar —xz -cvf /efs/backups/aws-us-west-www-prod-42-etc.txz /etc/

Gif 01. xz in action

Compress from stdin

$ mysqldump nixcraft-blog | xz > nixcraft-blog.sql.xz
Of coruse we can uncompress and send content to stdout for the mysql command too
$ xzcat nixcraft-blog.sql.xz | mysql nixcraft-blog
Let us uncompress tar directory from stdin sent from the nc, enter (assuming that target server-ip protected by VPN else use the ssh command):
$ nc -l -p 4242 | tar -xJvf —
On other side compress directory to stdout and send to the nc, run:
$ tar -cJvz — /var/www/html | nc server-ip-here 4242
Our final example use ssh instead of nc:
$ tar —xz -cf — /path/to/dir | ssh vivek@server1.cyberciti.biz «cat > filename.txz»
See “How To Use tar Command Through Network Over SSH Session” for more info.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Conclusion

This quick tutorial explained how to extract and unzip popular archive formats such as .tar.xz and .txz under Linux operating systems. Remember, tar command only works if you install the xz command via the package manager. See the xz project home page and docs here.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How To Extract Zip, Gz, Tar, Bz2, 7z, Xz and Rar File in Linux

An archive file is a file composed of one or more files in compressed format. It’s useful for saving disk storage, managing a single file is easier than managing multiple files. This tutorial will help you to decompress or extract an archive file in the Linux system via command line. You can also list archive file content without extracting it.

Extract .zip file in Linux

This is the most common compression format used by various IT professions on many operating systems. For this you must of unzip binary installed on your system.

Extract .gz file in Linux

Gz files are compressed files created using the Gzip compression utility. In general, GZIP is better compared to ZIP, in terms of compression, especially when compressing a huge number of files. Use gunzip command to extract .gz archive file.

Extract .tar file in Linux

Tar is the sort of Tape Archive and also referred to as the tarball. This is another popular archiving method which is also known as the consolidated Unix archive format. To extract .tar file use following command

Extract .tar.gz file in Linux

TAR.GZ file is a combination of TAR and GZIP archives. If provides more compression format of data. You can use -z switch to extract these files.

Extract .tar.xz file in Linux

The XZ format is a single file compression format and does not offer archiving capabilities. It preserves the original data with no loss in quality. You can use -J switch to extract these files.

Extract .tar.bz2 file in Linux

Tar.bz2 is an combination of tar and bzip2 archive formats. You can use -j to filter the archive through bzip2. Use the following to extract .tar.bz2 compressed file.

The latest version fo tar automatically detects the archive format. So you can simply use the following command.

Extract .7z file in Linux

These files are 7zip archive files. This is not generally used on Linux systems, but sometimes you may need to extract some source files. You must have the 7zip package installed on your system. Use the following command to extract these files.

Extract .rar file in Linux

These are common archive format for Windows systems, but Linux users avoid to use this. Still you may need sometimes to extract .rar file on Linux. You can use 7z command to extract this or unrar.

Источник

How to Extract (Open) a RAR File in Linux

RAR is a file format used for data compression and archiving. The RAR format supports data compression, error recovery and files archives. It also supports files larger than 4 gigabytes. RAR files can only be created through commercial software. You can extract rar file using free unRAR command line tool in Linux.

By default, unRAR is not being installed on Linux or UNIX distro. You need to install unRAR/rar tools with the help of below linux commands.

Install unrar/rar tool

If you are using Redhat Linux or Centos, then use yum command as follows to install unRAR command.

Listed below are some practical examples of RAR and unRAR command in linux to open,extract and compress files.

1. Extract (open) rar file

If you want to extract all files within the ‘.rar’ file in the current directory run below command

2. Extract files with full path

If you want to extract the files in full path. Run below command

3. List content of a RAR file

To list files inside rar archive file without extracting. Then use ‘l’ option

4. Check archive integrity

To test the integrity of file archive use ‘t’ option

5. Create a rar single file

To create a .rar archive file use ‘a’ option.

6. Create multiple rar files

To compress say ‘file1′, ‘file2′ and ‘file3′ simultaneously, use below command

You can also use the following method to RAR multiple files.

7. Set password for RAR file

While archiving, you can set a password (using -p option). If you omit the password on the command line, you will be prompted with a message “enter password” and the password is case sensitive.

Conclusion

In this tutorial we learned how to use rar/unrar command in linux to open,extract and create rar files. Hope you enjoyed reading this and please leave your comments below.

Источник

How to Extract RAR Files in Ubuntu Linux

What is a .RAR File Extension?

For users who don’t know, a RAR file is a compressed file that is split into a set of multi-volume files. This is usually done in cases where there are large file sets that are needed to be shared or transferred, hence are compressed into a zip file. Similarly, for zip files, when they are transferred or downloaded from the internet need to be extracted. A number of tools are available to help extract and compress these files within seconds, regardless of their size or quantity.

Extracting RAR Files in Linux distributions

RAR is a free tool that is pre-installed on Windows operating systems but unfortunately doesn’t support Linux platforms. If you will try extracting in Ubuntu, the archive manager will show you the following dialogue box:

This is because the system won’t recognize the file type like Windows and does not have any supported tool to extract it. In other cases, it will also display an error somewhat like this:

Read on below to find out how you can install RAR tools on Linux and use those to open, extract, and compress a file.

How to Install Unrar tool in Linux

Unrar is compatible mostly for Linux distributions where you can easily install the package from the command terminal using the apt programs.

Open Command Terminal and type the following command(s) if you’re using Ubuntu or Debian based distros:

If you are using Fedora distro, type the command in your command prompt:

For users using CentOS/ RHEL 64-bit distros, you can install the Unrar tool using these commands:

(Just remove ‘x64’ from the above command if you want to alter it for 32-bit systems)

How to Extract a RAR File in Linux

To open or extract a .rar extension file in your current working directory, type the following command in the terminal:

This will start extracting your file using the Unrar tool like this below:

Note: Since you have the Unrar tool, you can also perform these operations directly through the right click, besides using these commands on the terminal.

To open or extract a .rar extension file in any specific path or directory, type the following command in the terminal. This will extract the files and locate them in the specified directory.

If you want to open or extract a .rar extension file in their original directory, use the following command:

How to View Contents inside a RAR File in Linux

A compressed file contains multiple files of large sizes that are zipped together inside it. If you want to list out all the file contents inside an archive file, use the command below. This will display a list of files with their name, size, time, date created and permissions.

Testing a RAR File in Linux

If for instance, you have downloaded a file from the internet and would like to test its integrity, the Unrar tools offers that too. The following command will do a complete check on the archive file and its contents, and then show the results. Type:

The unrar tool that we just downloaded uses the unrar command to carry out the above tasks. It lets you extract, list out and test files. There is no option for creating a rar file with this particular tool. Therefore, we will install another Linux command-line utility called RAR to create compressed/archive files.

Installing RAR in Linux

To install the RAR command option, type the following commands in the terminal:

After you execute the commands, the result will be:

Creating RAR Files in Linux

In order to create a .rar file in Linux distribution, you will need to run the following command:

This will create an archive file name ‘filename’ for the directory filename1. See how this will look like below:

Deleting Files from any Archive

Out of the multiple files in an archive, if you want to delete a particular file through the command terminal, type the following command:

Recovering deleted Archives

If you deleted an archive file by accident or lost it through data loss, don’t worry, you can always recover it back. The following command will recover the file back or will fix it if there has been any loss or damage.

Setting password on a Particular Archive

This incredible Rar tool lets you do a number of interesting things with your archive files from creating, deleting, and adding, to changing their directories and protecting them through passwords.

If you want to protect your files from unknown access or extraction, you can set a password on them. To password-protect your file, type the following command:

Now, to verify the changes, type the command to open the directory to see if it asks for password.

Wrap Up

RAR and UNRAR are very useful when it comes to handling and managing files in Linux. They provide multiple options to make your work easier and more convenient. When compared to Windows, things get a little complicated for Ubuntu, but these commands are simple, easy to execute and give results within seconds.

If you need more description on the commands, just the run the following two:

Источник

Читайте также:  Brothers in arms earned in blood windows 10
Оцените статью