Saturday, July 27, 2013

Untar all files in a directory

#!/bin/bash
for a in `ls -1 *.tar.*`
do
        tar -zxvf $a
done

http://castyour.net/untar-all-files-directory

Bash for loop examples
http://www.cyberciti.biz/faq/bash-for-loop/

Other arguments
http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/


tar error - 'Child returned status 1'
http://www.linuxquestions.org/questions/linux-newbie-8/tar-error-'child-returned-status-1'-208083/

You used "tar -zxvf" for the second command. the 'z' option tells tar to use gzip to uncompress the file. Since you already uncompressed it in the first command, gzip doesn't know what to do with it, and it consequently croaks. Tar stops because gzip encountered a problem. So, with the file you have now, you would extract it with:
tar -xvf xxxxxx.x.x.tar

I would go back and re-gzip the tar file though (to save space):
gzip xxxxxx.x.x.tar
tar -zxvf xxxxxx.x.x.tar.gz


The first step uncompresses the tar ball.
In the second step, tar is expecting a compressed tar ball (.tar.gz).

You can either do:
Code:
tar -xvf fileName.tar
for an uncompressed tar ball
or 
Code:
tar -xzvf fileName.tar.gz
for a compressed tar ball, as the z switch uncompresses the tar ball using gzip.

I hope this helps
--Ian

No comments:

Post a Comment