Link to home
Start Free TrialLog in
Avatar of Paul_Jay
Paul_JayFlag for United States of America

asked on

Delete Original TAR Files After UNTAR

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
Avatar of svgmuc
svgmuc
Flag of United States of America image

You can run

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

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of svgmuc
svgmuc
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial