LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-26-2003, 04:06 PM   #1
jajanes
LQ Newbie
 
Registered: Jul 2002
Posts: 5

Rep: Reputation: 0
Talking Question regarding tar


I've (oddly enough) never run into this before, but I'm building a shell script that ftp downloads a group of tar files (via wget), then moves them into logical directories.

The problem I'm running into is this:

Multiple tar files end up in the same directory, and I won't always know the names of these files. How do I untar multiple files when the names won't always be the same?

aka my "logical" attempt at "tar xf /home/user/*.tar

doesn't quite make it. :-)

Any help would be seriously appreciated as this is yet another project I'm behind on. :-)
 
Old 07-26-2003, 04:42 PM   #2
enigmasoldier
Member
 
Registered: Jul 2003
Location: Florence, Ky
Distribution: CentOS 3.3-4, OpenBSD 3.3, Fedora Core 4, Ubuntu, Novell Open Enterprise Server
Posts: 213

Rep: Reputation: 30
xargs might help you with your problem

Links
http://www.datafocus.com/docs/man1/xargs.1.asp man xargs
http://unix.about.com/library/weekly/aa082001a.htm
http://www.iol.ie/~padraiga/cmdline.html
 
Old 07-26-2003, 04:48 PM   #3
jajanes
LQ Newbie
 
Registered: Jul 2002
Posts: 5

Original Poster
Rep: Reputation: 0
Talking Looks good -- thanks!

Looks good!

Thank you - I appreciate your help! (and so does my client -- at least by proxy) :-)
 
Old 07-26-2003, 04:52 PM   #4
Corin
Member
 
Registered: Jul 2003
Location: Jette, Brussels Hoofstedelijk Gewest
Distribution: Debian sid, RedHat 9, Suse 8.2
Posts: 446

Rep: Reputation: 31
If there are not too many tar files then you can always use shell expansion plus a loop to process them.

In Bourne shell --

for tar_file in *.tar
do
echo "Unpacking tar archive ${tar_file} ..."
tar xvf ${tar_file}
done

If there are hundreds of tar files then the expansion of *.tar on the line

for tar_file in *.tar

will become very long and exceed the maximum length for a line, and thus will have to use xargs as suggested above.
 
Old 07-26-2003, 05:00 PM   #5
enigmasoldier
Member
 
Registered: Jul 2003
Location: Florence, Ky
Distribution: CentOS 3.3-4, OpenBSD 3.3, Fedora Core 4, Ubuntu, Novell Open Enterprise Server
Posts: 213

Rep: Reputation: 30
I prefer to use the most scalable solution possible in everything I do. If it works on a large scale, then it works great on a small scale. A simple for loop works well, but breaks as you mentioned for large numbers of files
 
Old 07-26-2003, 05:35 PM   #6
Corin
Member
 
Registered: Jul 2003
Location: Jette, Brussels Hoofstedelijk Gewest
Distribution: Debian sid, RedHat 9, Suse 8.2
Posts: 446

Rep: Reputation: 31
Scalability is a good point.

But of course one should not try to stuff a directory too full of files!

So in the Linux tradition of there being more than one way to do it,
one could use find, especially if the tar archives were being downloaded into different directories

find path_to_archives -type f -name \*.tar -exec tar xvf {} \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 03:48 AM
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 11:55 AM
a tough question 4 u, problem in extracting tar & tar.gz files p_garg Linux - General 5 11-08-2010 12:02 PM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 07:30 AM
tar.gz question <---NOOOOOB QUESTION jairo Linux - Software 4 02-17-2003 06:28 AM


All times are GMT -5. The time now is 07:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration