Link to home
Start Free TrialLog in
Avatar of Cyber IT
Cyber ITFlag for United States of America

asked on

Removing files in UNIX

My company purchased a beta program that creates backup files in the format of backup.<date>. However they are put in different locations on the drive. Id like to be able to create a script to remove all files that start with backup. without looking through each folder.
Avatar of coanda
coanda

find / -type f -iname 'backup*' -exec rm {} \;
Avatar of Cyber IT

ASKER

Now will that way search the whole drive and delete all files with the backup name?

Can I prompt it for permission the first time and then delete it automatically afterwards?

Can I limit it to where it should search?
Avatar of ozo
Yes.

Yes, with a little more coding.

Yes.
to change which path is searched just replace / with whatever directory you want it to check. if you have sudo installed you can just add the sudo command to the front of the find command to run it as root, it will ask you to authenticate when you run it.
OK, I have files located in each month of the year and I wanted to delete all files with the backup in each month.  I dont want to browse and delete.

find / -type f -iname 'backup*' -exec rm -i -f -r {ls.. \January\backup}
find / -type f -iname 'backup*' -exec rm -i -f -r {ls.. \February\backup}
...

Am I off track here or is there an easier way??

Thanks!
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh, no ... I dont want to delete the directory... i just want to delete the files within the directories with that name scheme.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use a for loop to do for each month.So use something like this:

for month in January Febuary March April May June July August September October November December
do
find / -type f -iname 'backup*' -exec rm -i -f {ls.. \\$month\\backup}
done

Open in new window