LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Question regarding tar (https://www.linuxquestions.org/questions/linux-software-2/question-regarding-tar-76144/)

jajanes 07-26-2003 03:06 PM

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. :-)

enigmasoldier 07-26-2003 03:42 PM

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

jajanes 07-26-2003 03:48 PM

Looks good -- thanks!
 
Looks good!

Thank you - I appreciate your help! (and so does my client -- at least by proxy) :-)

Corin 07-26-2003 03:52 PM

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.

enigmasoldier 07-26-2003 04:00 PM

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

Corin 07-26-2003 04:35 PM

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 {} \;


All times are GMT -5. The time now is 10:53 AM.