Tuesday, June 12, 2012

xargs and using the stdin reference more than once

Multiple tar extractions in different directories based on the tar name.
computer:x usr$ ls -rtl
total 426552
-rw-r--r--  1 usr  usr  73451520 Jun 12 17:59 l01-2.tar
-rw-r--r--  1 usr  usr  72622080 Jun 12 17:59 l02-2.tar
-rw-r--r--  1 usr  usr  72284160 Jun 12 17:59 l03-2.tar
The only way I was able to do it is to push it into a small script, louzy.... I'll keep you posted on the alternatives.
computer:x usr$ cat test.txt 
mkdir $1 
cd $1 && tar xfv ../$1.tar && cd ..
computer:x usr$ ls -1 *.tar | sed 's/\.tar//' | xargs -I{} -t /bin/bash test.txt {} 

1 comment:

  1. One way is to use GNU Parallel:

    ls *.tar | parallel 'mkdir {.} && cd {.} && tar xvf ../{}'

    Learn more about GNU Parallel at: http://pi.dk/1

    ReplyDelete