Q. How do I extract a single file or directory form a tarball under UNIX / Linux shell prompt? How do I restore a single file from /dev/st0 tape device?
A. tar command allows to extract a single file or directory using the following format. It works under UNIX, Linux, and BSD operating systems.
tar xvf /dev/st0 filename
tar xvf /dev/st0 directory-name
tar xvf mytar.ball.tar filename
tar -zxvf mytar.ball.tar.gz directory-name
Extract file to /tmp directory
tar -zxvf mytar.ball.tar.gz -C /tmp filename
tar -zxvf mytar.ball.tar.gz -C /tmp dir-name
Read tar man page for more information:
man tar
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 5 comments… read them below or add one }
Hi,
I am running the same command to extract a directory from the tape backup. But its taking lot of time. So I have cancelled it
Could you tell me will it take time or else there is any other command which execute faster.
Thanks
Raju
Raju,
tar will take time, even when extracting a single file it will take a long time to complete if the tarball is big.
I know of nothing faster than tar to extract from a tar. Maybe just background the process and wait.
Cheers
Under windows, total commander or similar could do it faster ;)
No, there is no index in a tar archive, it is serial data. It doesn’t matter what operating system or what app you use, a tarball has to be read entirely before you know its contents.
Recovering from a tape is slower than disk. Be patient. Especially if you are retrieving a single file as mrpraline has explained it is a serial data file. If the file is at the end you will wait til the end before you even see the extraction. If the file is at the beginning, it will show its extracted and then you will wait a while before the command completes. If you want to reduce the time period of recoveries, say you are going to restore files more often, break them up into separate files. For example a tarball for /home and a tarball for /usr and /etc and / and /boot in another. That’s how I tar things up. One for the system and one for the actual user data. System is usually on my systems than data files.