Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

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.
0
Cyber IT
Asked:
Cyber IT
  • 3
  • 3
  • 3
  • +1
3 Solutions
 
coandaCommented:
find / -type f -iname 'backup*' -exec rm {} \;
0
 
Cyber ITEngineerAuthor Commented:
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?
0
 
ozoCommented:
Yes.

Yes, with a little more coding.

Yes.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
coandaCommented:
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.
0
 
Cyber ITEngineerAuthor Commented:
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!
0
 
ozoCommented:
find /January/backup  /February/backup -type f -iname 'backup*' -exec rm {} \;
0
 
coandaCommented:
CyberIT - the -r and -f commands are only necessary if you wanted to delete a directory and it's contents.
0
 
Cyber ITEngineerAuthor Commented:
oh, no ... I dont want to delete the directory... i just want to delete the files within the directories with that name scheme.
0
 
ozoCommented:
-type f
restricts you to finding only regular files, not directories or links or sockets,
see
man find
0
 
vikaskhoriaCommented:
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

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now