Solved

Removing files in UNIX

Posted on 2009-05-11
10
357 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
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

680 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