Results 1 to 5 of 5
Hi all,
I hope this is a simple question, but I have searched high and low and haven't found an answer. Is there a way to un-tar a bunch of ...
- 02-12-2006 #1Just Joined!
- Join Date
- Feb 2006
- Posts
- 3
un-tarring a bunch of files at once
Hi all,
I hope this is a simple question, but I have searched high and low and haven't found an answer. Is there a way to un-tar a bunch of tar.gz files at one time in a directory? I have about 500 tar.gz files that I want to untar, but it will only let me do it one file at a time (from the command line) e.g. if I tar -xzvf *.tar.gz, it just tells me that blah blah blah is not found in the archive. Any suggestions? the man page was no help.
Thanks in advance,
Jeff
- 02-12-2006 #2
hmm.. first check if you are in the correct directory. Use cd, if the tar files are not in your /home/whatever directory it naturally will not find it. You are correct in using the * for going for all the files with it. Also make sure they are all tar.gz files, as you'd have to do tar.bz2 also.
I know I stated the obvious and it may or may not have helped you but I'm stumped. If you can get into a DE like KDE or Gnome you can highlight all of the files, right click, and say extract to somewhere. I know you said you wanted to do it in CLI but whatever. good luckRegistered Linux user #393103
- 02-12-2006 #3Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
The DE trick will work but it will execute on all files at the same time and cripple your PC. If the wildcard isn't working for you try using a 'for' loop.
This particular command will only work on files without spaces. It will recursively act on each file, and you can pipe results to a file if you want to check back over it. If you need to act on files that contain spaces there'll be a bit more code to it, but this should get you started.Code:for i in `ls *.tar.gz`; do tar xvf $i; done
- 02-12-2006 #4Just Joined!
- Join Date
- Feb 2006
- Posts
- 2
This is what xargs is designed for - you need to pipe a list of your tar files, generated by `ls` or `find`, through to xargs which will run a command on each item passed - e.g.
{} is a variable that represents each element that the previous command, ls in this case, passed. `man xargs` should do the restCode:ls *tar.gz | xargs -t -i tar zxvf {}
- 02-13-2006 #5Just Joined!
- Join Date
- Feb 2006
- Posts
- 3
thanks guys, both of the ideas worked. I have combined the the two into a script file that I will find very useful for a long time.
jeff


Reply With Quote
