Possible Duplicate:
How to de-unzip, de-tar -xvf — de-unarchive in a messy folder?

This is a pretty annoying occurrence. Sometimes, I download an archive (tar.gz, tar.bz2, zip, rar, etc) and run tar xf [file] (or similar) in the file's directory. In rare occasions, all the files extract in the current working directory instead of a sub-directory. This can lead to hundreds of files and hundreds of patterns that can't simply be removed using a pattern matching solution.

Is there a way to get the file contents of an archive and then delete all files on that list in the current working directory?

link|improve this question

feedback

closed as exact duplicate by Gilles, Michael Mrozek Feb 14 at 4:26

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

2 Answers

up vote 7 down vote accepted

You can list the content of the archive and then pass the list to rm using xargs

Example for a tarball (test it without the rm first):

tar tfz archive.tar.gz | xargs rm -rf
link|improve this answer
Thank god you came around! – MaxMackie Nov 20 '11 at 16:32
feedback

Assuming all the files were extracted on the same date/time, you could write a one-liner and pass the regex to rm.

link|improve this answer
Could you elaborate a bit, in particular to distinguish your response from the already accepted one? Would the one-liner use find based on the mtime? And where do regexes come into this at all? – Kevin Feb 14 at 4:53
feedback

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