Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a USB containing important files. However it is infiltrated with some unwanted .exe files (probably virsuses) in each subfolder. Since I am on a Linux machine, the exe files won't affect me. However I want to remove them (for personal safety). So how do I do it using a Linux command or a shell/AWK or Python script.

share|improve this question

migrated from Oct 28 '12 at 21:17

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

up vote 3 down vote accepted
find /PATHTOUSBSTICK -iname "*.exe"

will show you all .exe files

If you are satisfied with the results (please check before deleting!) you can issue the following command:

find /PATHTOUSBSTICK -iname "*.exe" -exec rm {} \;

This will delete all matches found with the first command.

share|improve this answer
Make that "rm -- {}" to handle files whose name starts with "-". – Ed Morton Oct 27 '12 at 15:35

If you have GNU find available use -delete action:

find /path/to/files -type f -iname '*.exe' -delete
share|improve this answer

This will delete all the exe files present in your current and all its sub-directories:

 find . -name "*.exe" -exec rm '{}' \;
share|improve this answer


find . -name "*.exe" | xargs -n 1 -I {} echo "rm {}" >

check in your favorite editor; when you are happy:


to delete.

share|improve this answer

You must log in to answer this question.