1

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.

5
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.

  • 2
    Make that "rm -- {}" to handle files whose name starts with "-". – Ed Morton Oct 27 '12 at 15:35
1

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

 find . -name "*.exe" -exec rm '{}' \;
1

If you have GNU find available use -delete action:

find /path/to/files -type f -iname '*.exe' -delete
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy