Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
got a small script to uncompress and untar a bunch of files. The command works when I run it against 1 file on the command line, but when I stick it in a script in a for loop, it doesn't work. I've got
for file in `ls *.bd.tar.gz`
do
gzip -dc $file | tar xvf -
done
It's probably something obvious, but I can't see what it is. Any suggestions would be welcome.
What does "it doesn't work" mean? Any error message? Unexpected behaviour? Your script works fine for me, but I wonder what prevents you from using
Code:
tar xvf $file
instead of the gzip method. GNU tar should automatically take care of the compression (without specifying any additional option). Another note is about parsing the output of ls, which is not advisable for reasons expressed here.
got a small script to uncompress and untar a bunch of files. The command works when I run it against 1 file on the command line, but when I stick it in a script in a for loop, it doesn't work. I've got
for file in `ls *.bd.tar.gz`
do
gzip -dc $file | tar xvf -
done
It's probably something obvious, but I can't see what it is. Any suggestions would be welcome.
Hi,
I can also verify that the script works. So my guess is that your filenames might contain spaces. The for-loop will not process them properly in this case. That is why you should avoid parsing 'ls'. Try this instead:
Code:
for file in *.bd.tar.gz
do
gzip -dc "$file" | tar xvf -
done
yep, sorry about the lack of information re: the errors in the original post.
Getting 2 errors for each $file:
e.g. with a filename of jobs.bd.tar.gz
gzip: jobs.bd.tar.gz.gz: No such file or directory
tar: blocksize = 0
The gzip error message looks like it's appending an extra ".gz" to the end of the file name,
and the fact the .gz.gz file doesn't exist probably explains the 2nd message.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.