Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Removing files in UNIX

Posted on 2009-05-11
10
Medium Priority
?
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 84

Assisted Solution

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

Accepted Solution

by:
coanda earned 90 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 135 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

721 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