Linux untar one file

How to Untar a File in Linux

When you work with Linux, FreeBSD or other Unix implementations, you’ll often see files that end in .tar and may even have other extensions after it. Even some experienced users don’t know the simple way to extract these from a command line. Some users who are used to working purely from a command line might not know that they can also extract them graphically in most desktop environments.

Technically tar stands for tape archive, which reflects its original usage for creating tape backups on big iron computers. Many people refer to them as tarballs, so if someone tells you that a file is packed up as a tarball then this is the type of archive they’re talking about.

Method 1: How to Untar a File from the Command Line

You’ll need to first open up a command prompt using whichever procedure is most comfortable for you. Linux users can search for terminal from the Dash, click on Applications and then select System Tools or hold down Ctrl, Alt and T to start up a terminal window. You could also hold down Ctrl, Alt and a key from F1 to F6 to reach a virtual terminal, which will work as well. These commands should work from the terminal window in almost all other modern Unix systems as well.

Assuming you have a tarball archive in your current directory, simply type tar -xvf tarball.tar.gz to extract it. You’ll need to know the name of it. For the sake of illustration, we downloaded a tarball of Adobe Flash Player for Linux. Start by typing cd ~/Downloads to get to your downloads directory and then type tar -xvf flash_player_npapi_linux.x86_64.tar.gz to extract this file. That sounds like a ton of typing, but all you actually have to do is type tar -xvf fl and then start pushing the tab key. The command prompt will fill in the rest for you.

When you attempt to untar an archive, you might end up with an error message that reads something like:

tar: You must specify one of the ‘-Acdtrux’, ‘–delete’ or ‘–test-label’ options

Try ‘tar –help’ or ‘tar –usage’ for more information.

More than likely, you put a space between the – symbol and the xvf options on the command line. This makes it so that the tar program doesn’t know what options you’re using since it ends up thinking that xvf is part of the file name. You’ll need to either type tar -xvf flash_player_npapi_linux.x86_64.tar.gz or totally leave out the – and type tar xvf flash_player_npapi_linux.x86_64.tar.gz then push enter. You don’t actually need the – and can comfortably leave it off.

Читайте также:  Find files ending with linux

If you see a file that ends with .tar.bz2 or .tar.xz, then just follow the same procedure. You might even find ones that are shortened like .tgz or .txz, and you can use the same procedure to extract them too. The tar program will know the exact way to decompress them in most cases as long as you make sure to use tar -xvf or tar xvf first. The x tells it to extract the files from it, v tells it to be verbose and tell you what it’s doing and finally, the f tells it to point to the specific file you named.

Method 2: How to Graphically Untar an Archive

The command line is easier to use than a graphical file browser in most cases, but you can actually use Nautilus, Thunar or any of the other major file browsers integrated into your desktop environment if you’d like. It’s easy to untar files this way if you’ve just downloaded them and need to look right away.

Open your file browser by holding down the Super key and pushing either E in LXDE or F in Xfce4. You can start it from the Dash in Unity or the KDE menu in Kubuntu or any of the other major KDE-based distributions. Once you have it running, navigate to where your tar archive is. Right click on the archive or highlight it with the cursor keys and push the Menu key.

Select “Extract Here” and your desktop environment will automatically untar the archive right in the current directory.

Selecting “Extract To..” will instead open up a new dialog box that will allow you to select a location for where to put the files. This is a good idea if you already have other files or subdirectories inside of the directory that you’re in, which can make you lose whatever you’re extracting when you untar the archive!

Источник

How to Untar Files in Linux

Tar is quite a popular archive format, especially on Linux. In many cases, distros use tar archives to deliver package updates. Tar archives are also common to find when it comes to sharing files online.

Check out how to untar files in Linux.

Tar in Linux

For managing tar archives, all the Linux distros come with the tar tool. It’s this tool that we’ll use for extracting the contents of a tar archive.

Let’s demonstrate everything with an example. First, let’s create a tar archive with several files and directories. Here, I’ve created a directory with the name “Ants” that will be transformed into a tar archive.

Now, let’s make a tar archive out of the directory. Here, tar will use various compression algorithms to do the job. It’s a common practice that the compression algorithm dictates the output file name.

To create a tar archive using gzip compression, use the following command.

To create a tar archive using bzip2 compression, use the following command.

To create a tar archive using XZ compression, use the following command.

Extracting tar files

List tar content

The following tar command will list all the files and directories included in the tar archive.

Let’s have a quick breakdown of the flags we used.

  • t: It tells tar to list the contents of the archive.
  • v: It tells tar to print its action on console.
  • f: It tells tar which file to perform the action on.
Читайте также:  How to change resolution in linux mint

Extract entire file

Now, we’re ready to extract the tar archives we’ve got at hand. While you needed to use different commands to create different types of tar archives, we can use only a single tar command to extract all of them.

The following tar command will extract any valid tar archive. If files with similar filenames exist, upon extraction, tar will overwrite the files outside the archive.

Here, we’re facing one new tar flag.

If you don’t want tar to overwrite existing data, add the “-k” flag. It tells tar not to overwrite/replace any existing file or directory.

Extract specific files

There are some situations where you don’t need the entire tar archive extracted only to grab a single file. The tar tool offers such flexibility that you can extract only the select few files you need.

For this task, the tar command structure would look like this. Here, the file name would be the file name of your desired file. It must match with the file name that’s inside the tar archive.

If you want to extract a couple of files in such a manner, use the following command structure.

Extract specific directories

This is yet another awesome feature of the tar archive. Assuming the tar archive at your hand contains a directory or more, you can manually tell tar which directory to extract.

The command structure is similar to the section above.

If you want to extract multiple directories, then run the following command.

Final thoughts

Extracting tar archives is quite a simple task. All you need to know is the right tar command. If you’re interested in performing the actions with GUI and using a file manager, then your file manager should have the ability to extract tar archives by default.

In Linux, there are more tools to extract various formats of compressed archives. Check out how to extract compressed archives in Linux.

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.

Источник

Untar Tar.gz – Linux Tar Command – HowTo: Extract Tar File

Most of the Linux files that can be downloaded from the Internet are compressed with a tar , tar.gz and tar.bz2 compression formats and it is important to know how to extract such files.

The following article will help you to extract (unpack) and uncompress (untar) – tar , tar.gz and tar.bz2 files from the Linux command line.

You will learn how to list the contents of a tar archive without unpacking it and how to extract only a single file or a single directory.

File extension Description
tar Simple TAR archive without compression
tar.gz TAR archive compressed with GZIP
tar.bz2 TAR archive compressed with BZIP2

Cool Tip: No more wasted time! Download from the web and untar in one step from the Linux command line! Read more →

Untar tar, tar.gz, tar.bx2 Files

Extract and uncompress a tar.gz file:

Extract and uncompress a tar.bz2 file:

Option Description
-x Extract files from an archive
-v Verbosely list files processed
-f Specify an archive or a tarball filename
-z Decompress the contents of the compressed archive created by gzip program ( tar.gz )
-j Decompress the contents of the compressed archive created by bzip2 program ( tar.bz2 )

List the Contents of a tar, tar.gz, tar.bz2 Files

For example, it goes without saying, that it is inadvisable to untar the whole large archive if you need for example to extract only a dingle file or a directory from it.

Читайте также:  Linux ssh keys only

And of course this is possible with the Linux tar command, but firstly you need to check what is there inside the tarball without unpacking it.

List the contents of a tar file:

List the contents of a tar.gz file:

List the contents of a tar.bz2 file:

Cool Tip: There is no more need to remember all these -xvf , -xvzf , -xvif keys! This awesome bash function permits to extract any archive type with the single extract command! Read more →

Extract a Single File from a Tarball

Extract a file bar.txt , from an archive:

$ tar -xvf foo.tar bar.txt $ tar -xzvf foo.tar.gz bar.txt $ tar -xjvf foo.tar.bz2 bar.txt

You can also specify a path to the file:

$ tar -xvf foo.tar docs/bar.txt $ tar -xzvf foo.tar.gz docs/bar.txt $ tar -xjvf foo.tar.bz2 docs/bar.txt

Extract a Single Directory from a Tarball

Extract a folder, called docs , from an archive:

$ tar -xvf foo.tar docs $ tar -xzvf foo.tar.gz docs $ tar -xjvf foo.tar.bz2 docs

You can also extract some sub-directory:

$ tar -xvf foo.tar docs/images $ tar -xzvf foo.tar.gz docs/images $ tar -xjvf foo.tar.bz2 docs/images

Источник

How To Untar Files In Linux?

How To Untar Files In Linux?

The *.tar is a popular archive format used to compress files in Linux and Unix operating systems. The tar format is used with different compression algorithms like gz, bz2, etc. The most important function of the tar format is the ability to store multiple files and directories as a single file where it can be easily compressed. In the tutorial, we examine how to untar files with different compressions algorithms like gz, bz2 etc.

Untar Command Syntax

The tar command has the following syntax which can be used to untar files and folders in different ways.

tar OPTIONS TAR_FILE PATH
  • OPTIONS is used to untar different compressions formats.
  • TAR_FILE is the tar file.
  • PATH is optional and used in the tar file is extracted differently than the current working path.

Untar tar File

A tar file can be untared or extracted with the following command.

Untar tar.gz File

The tar files can be compressed with the gzip as gz format. In the following example, we extract the tar.gz file.

Untar tar.bz2 File

The bz2 is another popular compression format where tar can be compressed with it. The *.tar.bz2 can be untarred like below.

Untar To Specified Path or Folder

The untar operation extract files to the current working directory by default. But we can also specify another directory to untar a tar archive. The path can be specified with the -C option like below.

$ tar -xvf nmap.tar.bz2 -C /home/ismail/Downloads/

List Contents of tar File

A typical tar file contains lots of files and directories. The contents of the tar file can be listed with the following command.

List Contents of tar.gz File

List Contents of tar.bz2 File

Untar Single File

A single file can be untared from a tar archive. The file which will be extracted is added after the tar archive file.

$ tar -xvf nmap.tar.gz nmap/capsule.c

Untar Specific Extensions

Files with specific extensions can be untar using the tar command. In the following example, we untar files with *.txt extension.

$ tar -xvf nmap.tar.gz --wildcards "*.txt"

Untar Files with Specified Pattern

$ tar -xvf nmap.tar.gz --wildcards "Cache*"

Источник

Оцените статью
Adblock
detector