Results 1 to 6 of 6
I'm working (getting ready to) on a script that will delete backup files.
The find command works great, but I'm a little(OK ALOT) uncomfortable with using the rm command to ...
- 10-09-2007 #1Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
a question on the find command
I'm working (getting ready to) on a script that will delete backup files.
The find command works great, but I'm a little(OK ALOT) uncomfortable with using the rm command to remove as the backups are controled by root and as we all know a bad/blind rm command could wreck havoc on the server .
I tried to direct the output(>) to a file and I would then have that file as input to an rm command but I get nothing,not even the file created.
Here is the line command I'm using:
find .-name ''SERVERDB.*' +atime -100 > /home/server1/backup/delfile.log
but all I get is:
>
I then have to control c to break the command.
What am I missing and can someone help.
Yes this will be ran through roots cron
thanks
Mace
- 10-09-2007 #2Your SERVERDB.* is enclosed by a ", then a '. You probably meant to do this:find .-name ''SERVERDB.*' +atime -100 > /home/server1/backup/delfile.log
Here's a problem, though...$SERVERDB.* will expand to all files under SERVERDB, assuming SERVERDB ends in a /. -name can only take one argument. Are you trying to delete all of the files under SERVERDB? If so, this might do you better:Code:find . -name "$SERVERDB.*" +atime -100 ...
Code:find $SERVERDB +atime -100 -exec rm '{}' \;Flies of a particular kind, i.e. time-flies, are fond of an arrow.
Registered Linux User #408794
- 10-09-2007 #3Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
Javasnob..
thanks for the quick reply, the directory I'm working with will have several entries all with the same name(in fact the 1st 5 nodes are the same) and then the 6th node is a date/time .
So I'll only want to rm the oldest file in the dir.
I can find it with find, but I can't get that name to another file,
Or is thier an easier way than finding the file, moving it, then geting that file and rm ing it??
thanks
Mace
- 10-09-2007 #4
How about this?
... or, as a trial, just to see if it does what you want:Code:rm $(ls -t SERVERDB* | tail -1)
Hope this helps.Code:echo $(ls -t SERVERDB* | tail -1)
- 10-09-2007 #5
- 10-10-2007 #6Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
wje_lf
worked great
thanks
Mace


Reply With Quote