Solved

Removing files in UNIX

Posted on 2009-05-11
10
368 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
Supports up to 4K resolution!

The VS192 2-Port 4K DisplayPort Splitter is perfect for anyone who needs to send one source of DisplayPort high definition video to two or four DisplayPort displays. The VS192 can split and also expand DisplayPort audio/video signal on two or four DisplayPort monitors.

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
WARNING:   If you follow the instructions here, you will wipe out your VTP and VLAN configurations.  Make sure you have backed up your switch!!! I recently had some issues with a few low-end Cisco routers (RV325) and I opened a case with Cisco TA…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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