I have a bunch of tared and gz files. I saw how can I extract multiple gzip files in directory and subdirectories? i want something similar but first a new sub directory for each tar file.
All the archives are in one directory (say /u/z1/ with no sub directories in the beginning): 1.tar.gz 2.tar.gz
but they have similar files in the tars, say 1.txt, 2.txt
I do not want them over written.
So in generic bash script, want to iterate over all the files, make a sub directory with the same name as the file (/u/z1/gzs/1.tar.gz or 1.tar or just 1 is fine).
Then extract only the cuurent gz file to this new sub directory (cd to it?), then make a new directory 1.tar, under /u/z1/tars/ and untar the files to that directory.
Finally move to the next file and repeat. In the end we have directories: /u/z1/tars/1/, /u/z1/tars/2/, /u/z1/tars/3/ etc with respective files of that tar.
gzip
ped files don't have files "inside them". If you compress a file withgzip
, the resulting file doesn't know anything about the original file name. Are you maybe talking about compressedtar
archives (.tgz
or.tar.gz
)? – Philippos Jun 28 '17 at 14:16