How do I extract a specific file from a tar archive?

227,275

1. Using the Command-line tar

Yes, just give the full stored path of the file after the tarball name.

Example: suppose you want file etc/apt/sources.list from etc.tar:

tar -xf etc.tar etc/apt/sources.list

Will extract sources.list and create directories etc/apt under the current directory.

  • You can use the -t listing option instead of -x, maybe along with grep, to find the path of the file you want
  • You can also extract a single directory
  • tar has other options like --wildcards, etc. for more advanced partial extraction scenarios; see man tar

2. Extract it with the Archive Manager

Open the tar in Archive Manager from Nautilus, go down into the folder hierarchy to find the file you need, and extract it.

  • On a server or command-line system, use a text-based file manager such as Midnight Commander (mc) to accomplish the same.

3. Using Nautilus/Archive-Mounter

Right-click the tar in Nautilus, and select Open with ArchiveMounter.

The tar will now appear similar to a removable drive on the left, and you can explore/navigate it like a normal drive and drag/copy/paste any file(s) you need to any destination.

Share:
227,275
mx7
Author by

mx7

LinkedIn Profile: https://in.linkedin.com/in/raja-genupula-05205531 Endorse me If I helped you. Blog : http://thelinuxmen.blogspot.com/ Ubuntu - CentOS - Fedora - Windows - Severs - IIS - FTP - Security Thank you.

Updated on September 18, 2022

Comments

  • mx7
    mx7 over 1 year

    Is it possible to restore a single file from the .tar backup? I don't want to restore total backup. I just want to restore one single file from the backup.

  • CMCDragonkai
    CMCDragonkai over 10 years
    Is there some way to skip the first initial directory. Especially when I don't know the name of it? Like a like wildcard directory.
  • Jonathan Hagen
    Jonathan Hagen over 9 years
    Could you tell me if this loads in the entire tar file? Because when I tried to do this for a file (/etc/network/interfaces), it worked, but it tool ages. I stopped the program but the file was extracted.
  • Niloct
    Niloct over 9 years
    The crucial step for me was to use the full stored path of the file. So ./filename worked, but filename don't.
  • GKFX
    GKFX almost 8 years
    @ChristopheDeTroyer Tarballs are compressed in such a way that you have to decompress them in full, then take out the file you want. I think that .zip folders are different, so if you want to be able to take out individual files fast, try them.
  • beppe9000
    beppe9000 over 4 years
    Could you add more information on how to do it with Midnight Commander ?
  • ktaria
    ktaria about 4 years