How To Extract a Single File From a Large Tar file

[Total: 4    Average: 5/5]

How to extract a Single File From a Large Tar file?

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

Extracting Specific Files

Extract a file called etc/default/sysstat from config.tar.gz tarball

If you don’t know the exact location in tar file then you can first use the -tvf option to see the contents of tar file without extracting it.

[root@serverhost~]# tar -tvf config.tar.gz

Then you can use the following command to extract file.

[root@serverhost~]# tar -xvf {tarball.tar} {path/to/file}


[root@serverhost~]# tar -xvf config.tar.gz etc/default/sysstat

How to extract a Single Folder from tar file.

[root@serverhost~]# tar -zxvf config.tar.gz -C /tmp filename


[root@serverhost~]# tar -zxvf config.tar.gz -C /tmp folder-name

Read tar man page for more information:

  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar          # Extract all files from archive.tar.

 Main operation mode:

  -A, --catenate, --concatenate   append tar files to an archive
  -c, --create               create a new archive
  -d, --diff, --compare      find differences between archive and file system
      --delete               delete from the archive (not on mag tapes!)
  -r, --append               append files to the end of an archive
  -t, --list                 list the contents of an archive
      --test-label           test the archive volume label and exit
  -u, --update               only append files newer than copy in archive
  -x, --extract, --get       extract files from an archive

 Operation modifiers:

      --check-device         check device numbers when creating incremental
                             archives (default)
  -g, --listed-incremental=FILE   handle new GNU-format incremental backup
  -G, --incremental          handle old GNU-format incremental backup
      --ignore-failed-read   do not exit with nonzero on unreadable files
      --level=NUMBER         dump level for created listed-incremental archive
  -n, --seek                 archive is seekable
      --no-check-device      do not check device numbers when creating
                             incremental archives
      --no-seek              archive is not seekable
      --occurrence[=NUMBER]  process only the NUMBERth occurrence of each file
                             in the archive; this option is valid only in
                             conjunction with one of the subcommands --delete,
                             --diff, --extract or --list and when a list of
                             files is given either on the command line or via
                             the -T option; NUMBER defaults to 1
                             set version of the sparse format to use (implies
  -S, --sparse               handle sparse files efficiently