Cyber IT
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.
find / -type f -iname 'backup*' -exec rm {} \;
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?
Can I prompt it for permission the first time and then delete it automatically afterwards?
Can I limit it to where it should search?
Yes.
Yes, with a little more coding.
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.
ASKER
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh, no ... I dont want to delete the directory... i just want to delete the files within the directories with that name scheme.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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