In place untar and delete tar (or tar.gz)

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

Answers


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

Need Your Help

JSplitPane isn't shown

java swing jsplitpane

I have a problem with JSplitPane, I set the components to the JSplitPane but nothing is displayed.

Datagrid contents with UI Automation and .net

c# .net datagrid ui-automation

I'm having some trouble reading the contents of a Datagrid in an external application using UI Automation and could use some pointers. Here's what I have so far: