Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Linux User George Harrison's Avatar
    Join Date
    Mar 2005
    Location
    Pepperland
    Posts
    445
    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 luck
    Registered Linux user #393103

  3. #3
    Linux 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.

    Code:
    for i in `ls *.tar.gz`; do tar xvf $i; done
    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.

  4. #4
    Just 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.

    Code:
     ls *tar.gz | xargs -t -i tar zxvf {}
    {} is a variable that represents each element that the previous command, ls in this case, passed. `man xargs` should do the rest

  5. #5
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •