1

i want to decompress tar to specific folder, using random ( or anything else), because the content of tar is similar

In Win/batch random is used:

SET /A num=%random% %%100
for /d /r . %%d in (%folder%) do @if exist "%%d" ren "%%d" folder%num%

But in Linux/bash (???)

This is my case:

folder/1.tar 2.tar 3.tar.gz

cat *.tar.* *.tgz | tar -C folder/$RANDOM -zxvf - -i

example

folder/
   1/content of 1.tar
   2/content of 2.tar
   3/content of 3.tar.gz
| improve this question | | | | |
  • 1
    You're sending a stream of multiple tar files into a single tar. Try using a loop, like you're doing on Windows. – steve Oct 22 '16 at 22:02
0

This achieves what you're after

for F in *.tar *.tgz; do R=$RANDOM ; mkdir folder/$R ; tar -C folder/$R -zxvf $F -i; done
| improve this answer | | | | |
  • 1
    While probably not a problem to risk collisions with $RANDOM it might be better to use mktemp -d folder/XXXXXX or something like that to get the temp directory – Eric Renouf Oct 22 '16 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.