Find the answer to your Linux question:
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 ...
  1. #1
    Linux 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

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    find .-name ''SERVERDB.*' +atime -100 > /home/server1/backup/delfile.log
    Your SERVERDB.* is enclosed by a ", then a '. You probably meant to do this:

    Code:
    find . -name "$SERVERDB.*" +atime -100 ...
    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 $SERVERDB +atime -100 -exec rm '{}' \;
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  3. #3
    Linux 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

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    How about this?
    Code:
    rm $(ls -t SERVERDB* | tail -1)
    ... or, as a trial, just to see if it does what you want:
    Code:
    echo $(ls -t SERVERDB* | tail -1)
    Hope this helps.

  5. #5
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    If you have zsh:

    Code:
    rm ./SERVERDB*(Oa[1])

  6. #6
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139
    wje_lf

    worked great
    thanks
    Mace

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...