How to recursively remove all .exe files from all the subdirectories of the current directory?

1

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.

humanitarian0098

Posted 2012-10-27T11:29:24.577

Reputation:

Answers

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.

tom_ma

Posted 2012-10-27T11:29:24.577

Reputation:

2Make that "rm -- {}" to handle files whose name starts with "-". – None – 2012-10-27T15:35:06.850

1

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

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

Guru

Posted 2012-10-27T11:29:24.577

Reputation: 951

1

If you have GNU find available use -delete action:

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

Thor

Posted 2012-10-27T11:29:24.577

Reputation: 5 178

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.

user1772090

Posted 2012-10-27T11:29:24.577

Reputation: