I have this tiny code here
for i in *.tar.gz;
do tar xzvf $i;
done && find . -name "*.tar.gz" -exec rm {} \;
Now, when I have multiple tars, it will first untar all of them and then delete the tar files.
How can I change the code to untar a file, to delete it and then move to the next tar file?
Thanks in advance
Simply right-click the item you want to compress, mouseover compress, and choose tar. gz. You can also right-click a tar. gz file, mouseover extract, and select an option to unpack the archive.
In short, a TAR file creates one archive file out of multiple files without compressing them, while the GZ file format compresses a file without creating an archive. Combined into the tar GZ file extension, you can archive and compress multiple files into one.
We can also remove files from within the tar file with the --delete option. In the below example we remove the test2. txt file then list the contents of archive. tar which now only has test1.
Untar is defined as a command which enables users to extract files that are compressed with tar, tar. gz, tar. bz2 formats of compression. This command is used for 2 specific utilities in file operations.
for file in *.tar.gz; do tar xzvf "${file}" && rm "${file}"; done
Don't forget to quote your variables to account for funky filenames with whitespace.
Simply change the order of actions:
for i in *.tar.gz; do
tar xzvf "$i" && rm -r "$i"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With