Remove everything in a directory except the archive you just unpacked

Written by James McDonald

October 2, 2013

Just unpacked a zip file named CAT.zip 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 CAT.zip | xargs rm -rf

# delete everything except multiple files

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

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...