I have a tape with multiple tar files on it. I do not know how many (it was created by a third party and sent to me with minimal information). How do I untar all the files without having to repeat the tar -xvf /dev/st2 command 100 times. I need to repeat this for 45 tapes, each with possibly a 100 files
Asked
Active
Viewed 641 times
1
-
2Most *nix tape drivers have a non-rewinding variant (probably `/dev/rst2` in your case). Use that as the device, and look into the `mt` program, that allows you to forward- and backward-space over individual files on the tape. – Oct 30 '12 at 21:22
-
They put a 100 archives on each tape? Or one archive with a 100 files? – Hennes Oct 30 '12 at 23:06
-
Seems like it. Its from a third party, I am trying to follow up with them to find out why they did that! – Anu Oct 30 '12 at 23:56
-
Seems like a script is the way to go. ServerFault will not let me post an answer to my question until tomorrow...but the answer is a simple script with a loop in it to extract the tar files – Anu Oct 30 '12 at 23:56
-
A csh one liner might even be enough. Something using the return value from tar. E.g. while (! tar -xf /dev/nst0 ) echo "Another file done. Repeating for the next one!" – Hennes Oct 31 '12 at 00:35
-
Litte late, but closing the loop here. Hennes' answer worked. – Anu Sep 12 '13 at 19:37
-
@Anu - then you should give his question the checkmark to indicate this for future visitors – Mark Henderson Sep 12 '13 at 23:33
1 Answers
2
If the tape drive has a non-rewinding interface you can use a loop to extract one file after another.
Typical examples of tape drive name are: /dev/rst2
for raw access to a rewinding SCSI tapedrive, and /dev/nrst2
or /dev/tape/nrst2
for the same device without rewinding (non rewinding)
This can be combined with the exit code from tar. Like all unix program exit code 0 means "success, no problems."
This you can use a somewhat ugly one liner in a shell:
while (! tar -xf /dev/nst0 ) echo "Another file done. Repeating for the next one!"
Or write a somewhat neater program:
#!/usr/bin/env bash
return_value=0
counter=$1
while [ return_value -eq 0 ]
do
echo starting on file number $1
return_value=$(( tar -xf /dev/nst0 ))
echo file nu,ber $1 extracted from tape.
counter=$(( $counter + 1 ))
done
echo Reached end of tape or tar returned an error.
echo exiting.
Untested script!

Hennes
- 4,842
- 1
- 19
- 29