1834635 Members
3513 Online
110069 Solutions
New Discussion

Re: find command

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

find command

Hey guys,

what am I doing wrong here. I'm running this command and it doesn't seem to be doing what I'm asking.

find /home/jonny -name test.log.* -type f -mtime +14 -exec rm -f {} ;

I am running this out of my home directory. Trying to find for the file and remove it if the file hasn't been modified in over 14 days. Any help will be greatly appreciated.
9 REPLIES 9
Victor BERRIDGE
Honored Contributor

Re: find command

Hi
I think you forgot the backslash at the end of your line before the ;

All the best

Victor
James A. Donovan
Honored Contributor

Re: find command

try...
find /home/jonny -name "test.log.*" -a -type f -a -mtime +14 -exec rm -f {} \;

instead.
Remember, wherever you go, there you are...
James R. Ferguson
Acclaimed Contributor

Re: find command

Hi:

Do you have the backslash at the command's end (before the semicolon)?

# find /home/jonny -name test.log.* -type f -mtime +14 -exec rm -f {} \;

Regards!

...JRF...


harry d brown jr
Honored Contributor

Re: find command

Depending upon the shell, you should quote the name string because of the wild card.

find /home/jonny -name "test.log.*" -type f -mtime +14 -exec rm -f {} ;

live free or die
harry
Live Free or Die
Justo Exposito
Esteemed Contributor

Re: find command

Hi,

I Think that:
find /home/jonny -name "test.log.*" -a -type f -a -mtime +14 -exec rm -f {} \;

Regards,

Justo.
Help is a Beatiful word
harry d brown jr
Honored Contributor

Re: find command

If you left off the backslash, then you would get this error:

find: -exec not terminated with ';'

Probably a bad cut and paste ;-)

live free or die
harry
Live Free or Die
David Navarro
Respected Contributor

Re: find command

Hi,
Try this:

find /home/jonny -name "test.log.*" -type f -mtime +14 -exec rm -f {} \;

Best luck
A. Clay Stephenson
Acclaimed Contributor

Re: find command

Hi Sanman:

You have two problems:

1) As mentiopned you need the \ character before the ';'.

2) You need SINGLE QUOTES around your -n wildcard pattern because you do not want the shell toi expand the filename but rather you want to pass the wildcard string unmodified into find.

Regards, Clay
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor
Solution

Re: find command

And as a debug note: NEVER include the -exec option (especially with rm -f) until you are sure the find actually returns the names you expect. A catastrophic result will take place if you accidently put a space in front of the * for your -name parameter!


Bill Hassell, sysadmin