Deleting files in ubuntu linux

debonair

Well-Known Member
Joined
Sep 10, 2008
Messages
228
Reaction score
2
Location
Cape Town
I am a linux newbie and this is my situation

My other windows machine was badly hit by a virus that affects .exe files, this virus makes .exe files named after the folder it is in, .i.e if there is a folder called "folder" , inside that folder there will be a "folder.exe".

I copied the back up folder with all the files that I need to my linux box and what I want to do is to pass a command like, delete *.exe inside my backup folder. this should re-curse to all sub folders inside my backup folder.

I am not sure of the syntax or how to go about this, I do not want to go through each individual sub folder doing this.

thanks in advance,

Debonair
 
Hi,

This is a bit tricky. Do you have other .exe files in those directories (folders)? I know how to delete all .exe files recursively, but if there are .exe files that you want to keep, you will probably need a more complex script.

EDIT:
The script could look something like this:
Code:
DIRLIST=$(find . -type d ! -name '.' -exec basename {} \;)
for name in $DIRLIST
do
  find . -name "$name.exe" -exec rm {} \;
done
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X