I have a large tarball that is busy being FTP'd over from a remote system to our local system.

I want to know if it is possible to start untarring lets say 50 files at a time so that those files can begin being processed while the transfer takes place.

3 Answers 3


Here is a detailed explanation on how it is possible to extract specific files from an archive. Specifically 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.

For example:

tar --extract --file={tarball.tar} {file}

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.

  • 3
    I don't want to extract specific files. I just want to extract the first 50 files as I don't know what the names of the files are. Commented Jul 3, 2012 at 6:35
  • 4
    You can get a list of the filenames using "tar -tf", take the first 50 using "head", then feed that list into another tar command as the list of filenames to extract. Like this: "tar -xf file.tar --no-anchored `tar -tf file.tar|head -50`" Commented Jul 3, 2012 at 9:01
  • It is quite possible (in my testing) to extract a partially trandferred 50th file.. It would be a good idea to avoid extracting the (current) last file in the -t list until the tarball is fully downloaded. At any point of time, the list shows only filenames which have been, or are being, transferred, ie. not the full list; until it is fully downloaded.
    – Peter.O
    Commented Jul 4, 2012 at 3:36
tar -tvf tarfile.tar

gives you the whole list of files in tarfile.tar

tar -xvf tarfile.tar fileToRestore  

This command restores the fileToRestore

To untar multiple files, but not all of them you can:

  • You put all file list from tarfile.tar into tar.txt

    tar -tvf tarfile.tar > tar.txt
  • Now tar.txt has the whole list of files in tarfile.tar and you can leave only the files you want to restore or with head...

    head -n50 tar.txt > tar2.txt

You can put these lines into a file

cat tar.txt|while read line
   tar -xvf tarfile.tar ${line}

Or the complete script file:


if [[ "$1" = "" || "$2" = "" ]]
   echo ""
   echo "Uso: untar-list.sh tarfile.tar listfile.txt"
   echo ""
   exit 1


if [[ ! -f ${tarfile} ]]
   echo ""
   echo "Archivo ${tarfile} no existe"
   echo ""
   exit 1

if [[ ! -f ${file} ]]
   echo ""
   echo "Archivo ${file} no existe"
   echo ""
   exit 1

cat ${file}|while read line
  tar -xvf ${tarfile} ${line}

echo ""
echo "Finalizado"
echo ""

And that's all

  • 2
    That has to be painfully slow to call the tar command in a loop. It reads the the whole file each time, right?
    – swdev
    Commented Nov 20, 2014 at 17:58

Didn't try this myself, but how about this:

tar xvf archive.tar | head -n50

Tar outputs a line to STDOUT for each file extracted, then the head command will kill the pipe after 50 lines. Upon the pipe dying, I'd expect the tar to die too.

  • Sorry, that should of course been a head. Let me change my answer.
    – jippie
    Commented Jul 3, 2012 at 21:36
  • I haven't checked, but I fear that due to the pipe buffer, tar may extract more than 50 files before it's SIGPIPEd, and in particular it may extract the last, incomplete file. Commented Jul 3, 2012 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .