Find Syntax

Drew Tomlinson drew at mykitchentable.net
Mon Jan 2 10:13:17 PST 2006


On 1/2/2006 9:59 AM Kevin Brunelle said the following:

>>OK, I understand now.  I ultimately want to delete files and was just
>>trying to check my command before doing the actual delete.  I will use
>>'-ls' in my script.
>>
>>    
>>
>>>find . -type f -mtime +1w -exec ls -l {} \;
>>>      
>>>
>>This works too.  Thanks again!
>>    
>>
>
>What is your intent with the -ls?  Do you need the full listing because I find 
>that if I just want to know what files are removed the "-print" switch is 
>cleaner.  Or, once I am comfortable that the command is doing what I want, 
>leaving off the output entirely.
>  
>

I'm running ntop with the rrd plugin and found that it quickly filled my 
drive.  My intent is to delete rrd files that are older than so many 
days to save disk space.  I just wanted to verify that my '-mtime' was 
returning the results I expected before actually deleting.  'ls -l' 
keeps the date in the same place on the screen so I can scan with my 
eyes as the results scroll by.  Once I verify I'm getting the results I 
want, '-ls -l' is no longer needed.

>For my temp file deletions I use 
>
>/usr/bin/find /home/kevinb/tmp -atime +3 -exec rm {} \;
>  
>

'-delete' can be used in place of '-exec rm {} \;".  I suspect '-delete' 
is more efficient but it's just a guess.

>Yes, I keep my own tmp/ directory below my home directory (it's an old habit).  
>This command deletes anything I haven't accessed in three or more days.  I 
>use access (-atime) here but modification works just as well.  I have that in 
>a script which cron runs once a day so I can use my temporary folder and not 
>worry about cleaning up after myself... and I know that anything I put there 
>I expect to lose unless I find a reason to keep it and move it somewhere 
>else.
>
>As a word of warning, don't run this in your home directory or in a location 
>where there are files which will sit around without being used for months at 
>a time.  You would really be upset if ~/.cshrc happened to vanish or any 
>other file you rely on but don't think of.
>  
>

I've got things working now.  Thanks for your help!

Drew



More information about the freebsd-questions mailing list