Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used "unzip" to extract a zip file, unfortunaly, i make a mistake.

Now i want to delete all the file and directorys generated by "unzip".
How can I undo it?

share|improve this question

migrated from Feb 1 '12 at 3:19

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 16 down vote accepted

use this:

unzip -l filename |  awk 'BEGIN { OFS="" ; ORS="" } ; { for ( i=4; i<NF; i++ ) print $i " "; print $NF "\n" }' | xargs -I{} rm -v {}

Use this if you are skeptical (will prompt for confirmation)

unzip -l filename |  awk 'BEGIN { OFS="" ; ORS="" } ; { for ( i=4; i<NF; i++ ) print $i " "; print $NF "\n" }' | xargs -I{} rm -iv {} 
share|improve this answer
Fails if any files have spaces in their names... (+1 now with the -i edit. :) –  sarnold Feb 1 '12 at 3:17
The problem is in the awk '{print $4}' -- a filename with spaces might be in $4 $5 $6 .... :) –  sarnold Feb 1 '12 at 3:24
Ok. Fixed that too. –  shadyabhi Feb 1 '12 at 3:29
Thanks very much, awk might be the best solution –  hero2008 Feb 1 '12 at 5:14
FTR this also deletes the original zip file –  sjr Jun 14 '14 at 15:39

You're in a rough spot; the standard zipinfo(1) utility doesn't provide any mechanism to get unambiguous filenames out of an archive. But, you can come close:

zipinfo -1 /path/to/zip/ | xargs -d '\n' rm -i

If you're sure none of the files have newlines in them, you can remove the -i option to rm(1) (which will surely get tedious).

share|improve this answer

If you want to clean up your directory after accidentally unzipping without creating a folder first, you could create the folder, unzip to that and then:

rm -r ` ls folder `

" ` " is super useful for chaining commands but it's very literal.

share|improve this answer
apologies for rushing to the incorrect syntax, can the vote down be removed? –  chrispepper1989 Aug 25 '14 at 13:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.