Tar Extract a Single File(s) From a Large Tarball

Q. I’ve couple of large tarballs such as www.tar and images.tar. Is it possible to extract a single file or a list of files from a large tarball such as images.tar instead of extracting the entire tarball? How do I extract specific files under Linux / UNIX operating systems?

A. GNU tar can be used to extract a single or more files from a tarball. To extract specific archive members, give their exact member names as arguments, as printed by -t option.

Extracting Specific Files

Extract a file called etc/default/sysstat from config.tar.gz tarball:
$ tar -ztvf config.tar.gz
$ tar -zxvf config.tar.gz etc/default/sysstat
$ tar -xvf {tarball.tar} {path/to/file}

Some people prefers following syntax:
tar --extract --file={tarball.tar} {file}
Extract a directory called css from cbz.tar:
$ tar --extract --file=cbz.tar css

Wildcard based extracting

You can also extract those files that match a specific globbing pattern (wildcards). For example, to extract from cbz.tar all files that begin with pic, no matter their directory prefix, you could type:
$ tar -xf cbz.tar --wildcards --no-anchored 'pic*'
To extract all php files, enter:
$ tar -xf cbz.tar --wildcards --no-anchored '*.php'


  • -x: instructs tar to extract files.
  • -f: specifies filename / tarball name.
  • -v: Verbose (show progress while extracting files).
  • -j : filter archive through bzip2, use to decompress .bz2 files.
  • -z: filter archive through gzip, use to decompress .gz files.
  • –wildcards: instructs tar to treat command line arguments as globbing patterns.
  • –no-anchored: informs it that the patterns apply to member names after any / delimiter.

Further readings:

  • GNU tar man page

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 22 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
22 comments… add one
  • sathiya Dec 6, 2008 @ 11:42

    excellent article..

  • ruben Dec 8, 2008 @ 8:13

    I suggest getting coffee especially, Extracting files from large tar files.
    Instead of using tar, it’s far better to use zip as methode. the reason for this is that zip knows where the files are.

    We have some 4 Gb tar files and extracting a couple of single files with tar can take up to 25 minutes.

    My 2 cents,


    • Anonymous May 12, 2010 @ 4:10

      good advice, I am waiting here for a file to be extracted from a 7GB tar file which is stored on a different computer. Its going to be a long night I think.

      • another ruben Nov 4, 2014 @ 20:37

        I got ahold of a dataset that contains extracts of different research papers. After extracting them I went to verify them I saw one file was empty. Checked the rest of the files and for some reason this is the only one.

        Thinking there might have been a problem, I decided to reextract that file again.

        It’s a 65GB tar.gz file.

        It finished this morning. The file was indeed empty and it wasn’t an error. Days wasted for that…

  • elinus liga Dec 15, 2008 @ 11:09

    Excellent post. It’s really useful. Clear, simple and just as what we need.

  • zaffar Dec 22, 2008 @ 12:12

    excellent article for new bie

  • kpb Feb 24, 2009 @ 1:33

    Great article!
    Keep it coming!

  • Jatin Apr 22, 2009 @ 11:40

    Great help !!! thanks ..

  • subba May 15, 2009 @ 4:43

    Good one! Thanks a lot!

  • Asad Kahwaja Jun 23, 2009 @ 19:08

    My problem is that i have downloaded a movie.
    But my mvie is corrupt in da end
    now i have downloaded 8th part of the movie.
    but when i extract it
    i gives me error
    is dere any way i can resole this n can only extract on file.

    • Maurzanc Aug 20, 2010 @ 23:31

      I think you are talking about a multiple RAR archive downloaded from a torrent client. if it is, you have search the answer in other forum.


  • Kevin H Jul 28, 2009 @ 20:48

    is there a way to use regexp matching rather than wildcard matching with tar?

  • Prafull Dec 20, 2010 @ 9:54

    On Solaris 10 if you have a tar ball called myTarfile.tar and you want to extract only one directory called my_dir from that tar file then below command workes

    tar -xvf myTarfile.tar -C my_dir

  • Dmitry Jul 1, 2011 @ 16:19

    For better speed and low cpu usage use pbzip2, very good work with big archives on hosting systems.

  • Yan.Geema Jul 11, 2011 @ 15:11

    Very useful.


  • reetesh Jan 11, 2012 @ 3:15

    thanks…good to know

  • Balaji Jan 27, 2012 @ 6:50

    Thank you very much. Timely help.

  • bababab Feb 28, 2012 @ 15:02

    there is need to type command in proper way with proper

    symbols and spaces tar -xvf {tarfile} {file} or {{path}/{file}}.

    Example: tar -xvf file.tar myfold/file

    same with tar.gz types just instead of -xvf , -xvzf should be

    typed. or if with -C option then:

    Example : tar -xvf file.tar -C /newfold myfold/file

  • shakeel Mar 13, 2012 @ 18:05

    i have a file in format gz type any bady can help me plz help me opening this file

  • dexter Mar 20, 2012 @ 15:52

    Thanks for the post!

    I have a 68gb tar.gz backup of our website, and I need to extract a single file from it..

    $ tar -zxvf config.tar.gz home/path/to/folder/*

    Is the above line correct?

    • ab Nov 5, 2015 @ 17:00

      `tar tvzf config.tar.gz ` with the -t flag instead of -x will list the files in the archive. From this output it will be easier to extract specific files/folders, just copy & paste the path/file you want from it. `tar xvzf config.tar.gz path/to/file`

  • Yann Laviolette Apr 25, 2013 @ 15:14

    Thanks a lot! It was exactly was I waiting for…

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum