LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-18-2003, 01:58 PM   #1
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Rep: Reputation: 30
Wink unpacking multiple .tar.gz files


i have a directory full of tar.gz files. i want to unpack all of them into a directory.

tar zxvf filename.gz for a single file but what about multiple files.

i want to do all of them at once is there a way to do this I'm not sure how i tried tar.zxvf *.gz but that didn't work.

thanks,
AD
 
Old 01-18-2003, 02:36 PM   #2
mhearn
LQ Guru
 
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 57
try this:

for a in `ls -1 *.gz`; do tar xzvf $a; done
 
Old 01-18-2003, 03:01 PM   #3
oot
Member
 
Registered: Dec 2002
Distribution: Slackware 12.0
Posts: 240

Rep: Reputation: 30
I'm assuming that by didn't work, you mean it put them in seperate folders. I don't know how to make it all untar into the same folder, but here's a script that will take the files from the seperate folder and put them all into one. Copy and paste the script below into a new text file (Leave out the lines that mark the beginning and the end) in the directory containing the directories your files were untarred into, call it something like move.sh. Then run "chmod u+x <name of script>" and then run "./<name of script>"

---Begin script---
#!/bin/sh
#This script takes files in all subdirectories of the current directory except DEST_DIR and copies them into DEST_DIR
DEST_DIR=all_files #Edit this to point to the folder you want

if [ -d $DEST_DIR ]
then
for file in *
do
if [ -d $file ]
then
if [ $file != $DEST_DIR ]
then
cp -R $file/* $DEST_DIR
fi
fi
done
else
echo "Error: $DEST_DIR does not exist or is not a directory."
echo "To set the destination directory, edit this $0 and set DEST_DIR."
fi
---End script---
 
Old 01-18-2003, 04:54 PM   #4
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Original Poster
Rep: Reputation: 30
mhearn,

thanks man worked like a charm. how the hell did you figure out the command. i tried tar --help and looked through all of the different options with no luck.

i havent tried the script yet oot thanks


ahhhh,
thanks man
 
Old 01-18-2003, 05:14 PM   #5
mhearn
LQ Guru
 
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 57
I am a bash programmer in my spare time, I use it in the autopackage project.

ls -1 gives a list of each file on a newline, the wildcards (filename globbing) should be obvious, it's the same as in dos.

for varname in[list];

list is a string split using the contents of the IFS special variable, in this case set to a space, so this script will fail if any of the files have a space in the same. The backtick ` operator executes the command inside it and substitutes the output (in this case, the newlines are turned into spaces). Therefore varname is set to each file in turn.

tar xzvf $varname;

extracts the file and "done" indicates the end of the loop.

Basic shell programming. You've gotta love bash.
 
Old 01-18-2003, 05:43 PM   #6
illtbagu
Member
 
Registered: Dec 2002
Location: Nevada
Distribution: fedora, RHEL, ubuntu, suse
Posts: 343

Original Poster
Rep: Reputation: 30
way coooooool thanks man.

AD
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
extracting multiple files with tar -xjvf logicalfuzz Linux - Software 3 11-06-2005 01:21 AM
Need some help w/ unpacking a tar.gz & directory stuff davidbix Linux - Newbie 2 10-21-2005 07:01 PM
Unpacking a .tar.bz2 file njschroe Linux - Software 1 01-31-2005 03:25 PM
unpacking .tar.gz files crazibri Linux - Newbie 5 03-24-2004 02:19 AM
unpacking tar file Longinus Slackware 4 12-14-2003 02:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:42 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
Open Source Consulting | Domain Registration