I have a folder containing many tar archives
- archive1.tar
- archive2.tar
- ...
I'd like to write a bash script which extracts their innard files to separate folders:
- archive1
-
- file1-1
-
- file1-2
-
- ...
- archive2
-
- file2-1
-
- file2-2
-
- ...
- ...
My best shot so far is this script:
for file in ./*tar; do tar -xf $file -C .; done
The problem with it is that it just dumps all the files into the . folder.
I'm really puzzled about how can I specify the destination folder after -C, or there is another way to make this work.
CodePudding user response:
Create a subdirectory named after the tarfile and use that instead of .
for file in *.tar; do
dir=$(basename "$file" .tar)
mkdir "$dir"
tar -xf "$file" -C "$dir"
done