Remove everything in a directory except the archive you just unpacked

Written by James McDonald

October 2, 2013

Just unpacked a zip file named and it exploded into hundreds of files and directories.

This is what I did to get rid of the contents of the extracted archive excepting the archive itself.

Warning: Don’t do this in directory that has many files you want to keep

# delete everything except a single file
ls -1 | grep -v | xargs rm -rf

# delete everything except multiple files

ls -1  | grep -v -e '' -e 'skip.txt' | xargs rm -rf


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...

PC Build

I recently built myself a PC using the SilverStone SG13 Case. I am planning to use it as a Hot Spare. So any client...