Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Oct 28 '12 at 21:17

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

4 Answers 4

If you have GNU find available use -delete action:

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

Run

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

check tmp.sh in your favorite editor; when you are happy:

/bin/sh tmp.sh

to delete.

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

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

Your Answer

 
discard

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