Help on untar files in one command

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on untar files in one command
# 1  
Old 09-19-2011
Help on untar files in one command

Hi All,

I need your help to find out an easy way to untar files from a tar file.

For example, I have a tar file which contains a lot of files that needs to untar in certain directories. I would like to untar them using one command instead of typing the following commands which is taking lots of time. Is there an easy way to do that?
tar -xvf ABC.tar bin/file1
tar -xvf ABC.tar bin/name
tar -xvf ABC.tar bin/address
tar -xvf ABC.tar bin/status
tar -xvf ABC.tar bin/city
tar -xvf ABC.tar bin/country

tar -xvf ABC.tar lib/file7
tar -xvf ABC.tar lib/post
tar -xvf ABC.tar lib/get

Last edited by Scott; 09-19-2011 at 12:36 PM.. Reason: Code tags
# 2  
Old 09-19-2011
How many files?

tar -xvf ABC.tar bin/file1 bin/name bin/address bin/status bin/city bin/country lib/file7 lib/post lib/get

# 3  
Old 09-19-2011
Thanks for your quick response. I have about 35 files in bin and 74 files in lib to untar. I think I can put them in a input file then run it as following...
for i in `ls tar_list`
tar -xvf ABC.tar $i

any other easy thoughts?

Last edited by Scott; 09-19-2011 at 01:07 PM.. Reason: Added code tags
# 4  
Old 09-19-2011
Not sure what "tar_list" is. A file containing a list of the files to untar, I presume, so that should probably be "cat tar_list"?

No need for the cat, anyway:

while read i; do
  tar -xvf ABC.tar "$i"
done < cat_list

# 5  
Old 09-19-2011
yes tar_list contains all the untar file lists. sorry, I actually meant
for i in `cat tar_list`
tar -xvf ABC.tar $i

thank you for your help

Moderator's Comments:
Mod Comment Please use code tags...

Last edited by Scott; 09-19-2011 at 01:53 PM.. Reason: Code tags
# 6  
Old 09-19-2011
As I said, there's no need for "cat".

A shorter alternative:

xargs < tar_list -I{} tar xf ABC.tar {}

(you can add the xargs -n option if there's too many files)
# 7  
Old 09-19-2011
That's a useless use of backticks and useless use of cat and almost always better done as

while read LINE
done < filename

As for how to feed all those filenames into tar, if none of the files contain spaces or quotes in filenames, it's easy enough, use xargs. "echo a b c | xargs command" amounts to "command a b c", and it can read from a file.
xargs tar -xvf filename.tar < tar_list

If possible it will squeeze it alll into one tar call, but for too many files, it may have to break it into a few.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

tar and untar the files using single line

Hi, i want tar the files from one location and untar it to other location using single line. Can any one help me zip and unzip using single line command. (2 Replies)
Discussion started by: venikathir
2 Replies

2. Shell Programming and Scripting

cp, chown, untar

hello i want shell script. i have a source.txt /home/user409/public_html/test/ /home/user09876/public_html/xdsss/ /home/user9765/public_html/320xxx/ . . . maybe 1000 lines i want . a source.txt 2.untar special.tar.gz into these directory in source.txt 3.i want to... (14 Replies)
Discussion started by: topic32428285
14 Replies

3. Shell Programming and Scripting

Untar files from different locations

Hi all, My tar file exists in directory: /usr/users/rovolis/test1/archive.tar Now from directory: /usr/users/rovolis/ i run the following command tar xvzf /usr/users/rovolis/test1/archive.tar The problem is that the extraction of files is not done Any idea why? Thank you (1 Reply)
Discussion started by: chriss_58
1 Replies

4. AIX


Hi, How can i untar a set of files in to different directory. This is content tar -tvf samba.tar drwxrwxrwx 0 0 0 Nov 28 18:35:41 2008 samba/ -rw-r--r-- 0 0 0 Nov 18 15:12:40 2008 samba/b.txt -rw-r--r-- 0 0 0 Nov 18 15:12:40 2008 samba/c.txt -rw-r--r-- 0... (4 Replies)
Discussion started by: allwin
4 Replies

5. Shell Programming and Scripting

Shell script required to uncompress and untar files

I need a shell script to Uncompress untar all the files present in the directory (it should Uncompress an untar files present in its sub folders also) In my work I get lots of tar files to untar and update the server, for this each time in need to type Step1) Uncompress xyz1-3.tar.z... (2 Replies)
Discussion started by: arewe
2 Replies

6. Shell Programming and Scripting

Untar remotely

I need to upload tar or zip files to a unix server than unzip or untar them remotely. Any suggestions on the easiest way to do the remote untar or unzip? For example does someone know of a cgi script or something? Thanks -jz (3 Replies)
Discussion started by: jwzumwalt
3 Replies

7. UNIX for Advanced & Expert Users


i have try to untar the file in same location. But it gave the error # tar -xvf TSMSRVAIX5220.tar x tivoli.tsm.devices.acsls, 757760 bytes, 1480 media blocks. tar: 0511-169 A directory checksum error on media; 4011 not equal to 8222. How can i rectify this prob. Thanks in advance ... (2 Replies)
Discussion started by: prakash96453
2 Replies

8. UNIX for Dummies Questions & Answers

How can you UnTar files to a different directory?

Suppose you have a TAR file created with a different directory structure and you need to UnTar (or explode) the files to a different directory structure. How can this be done? If TAR command cannot do this, are there any other alternatives (any other command) available to UnTar a .Tar file? ... (1 Reply)
Discussion started by: joshivaibhav
1 Replies

9. UNIX for Dummies Questions & Answers

how to untar *.dpk files

Hi All, I am unable to untar *.dpkg.md5 using tar command. Could nay one help me out. Thanks & Regards Gauri (3 Replies)
Discussion started by: gauri
3 Replies

10. Shell Programming and Scripting

Writing a shell script to untar files

I am new to shell scripting and would appreciate any help I can get. I need to write a Unix shell script that I will run whenever I have a tar file to uncompress(Korn shell). Please put in mind that I have different environements that I will run it on. Thanks in advance ;) (4 Replies)
Discussion started by: nkem22
4 Replies
Login or Register to Ask a Question