Solved

Removing files in UNIX

Posted on 2009-05-11
10
337 Views
Last Modified: 2013-12-23
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
Comment
Question by:Cyber IT
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 3

Expert Comment

by:coanda
ID: 24357905
find / -type f -iname 'backup*' -exec rm {} \;
0
 

Author Comment

by:Cyber IT
ID: 24358218
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
 
LVL 84

Expert Comment

by:ozo
ID: 24358591
Yes.

Yes, with a little more coding.

Yes.
0
 
LVL 3

Expert Comment

by:coanda
ID: 24358659
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
 

Author Comment

by:Cyber IT
ID: 24358997
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 84

Assisted Solution

by:ozo
ozo earned 45 total points
ID: 24359043
find /January/backup  /February/backup -type f -iname 'backup*' -exec rm {} \;
0
 
LVL 3

Accepted Solution

by:
coanda earned 30 total points
ID: 24359168
CyberIT - the -r and -f commands are only necessary if you wanted to delete a directory and it's contents.
0
 

Author Comment

by:Cyber IT
ID: 24359417
oh, no ... I dont want to delete the directory... i just want to delete the files within the directories with that name scheme.
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 45 total points
ID: 24359460
-type f
restricts you to finding only regular files, not directories or links or sockets,
see
man find
0
 
LVL 5

Expert Comment

by:vikaskhoria
ID: 24372778
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SBS 2011 wireless nic? & dynamic VPN. 3 66
Unknown security group 2 59
Which Switch is Switch - improving performance 9 45
Viber-Only Restriction 6 26
This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now