Delete Original TAR Files After UNTAR

Paul_Jay
Paul_Jay used Ask the Experts™
on
I am running this command on HP UNIX.  I have 60 tar files that contain multiple files totaling about 2GB of data in each tar file.  The following command is working fine to extract the files.  The issue is I don't have enough disk space for all the .tar files and the .dat files it contains to exist at the same time.  I want to extract data from FILE1.tar to FILE1A.dat, FILE1B.dat and then delete FILE1.tar before moving on to file FILE2.tar.  Is there a way to automatically delete the .tar file once the data has been extracted to the .dat file?  

for tarfile in *tar;  do tar -xvf $tarfile; done
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You can run

for tarfile in *tar;  do tar -xvf $tarfile; rm $tarfile; done

Author

Commented:
That seems to work!  I've seen references to using && before a command to only run if previous command ended successfully.  Would that be useful in this case?
Commented:
Definitely.

for tarfile in *tar;  do tar -xvf $tarfile && rm $tarfile; done

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial