Operating System - HP-UX
1834103 Members
2486 Online
110063 Solutions
New Discussion

find command - how to exclude subdirectories and files within subdirectories

 
SOLVED
Go to solution
Paul Ammirata
Occasional Contributor

find command - how to exclude subdirectories and files within subdirectories

I want to find all files in /tmp that are more than two days old, but don't want to include any directories within /tmp or any files within those directories in the results. How do I exclude directories in /tmp and files within those directories? I thought I should use -prune or -only, but am not getting the results that I want.

Here's what I have so far:

find /tmp -name \* -a -mtime +48 -print

Any help would be appreciated.
5 REPLIES 5
Rodney Hills
Honored Contributor
Solution

Re: find command - how to exclude subdirectories and files within subdirectories

The -path and -prune option of find is helpful in this case.

find /tmp -path "/tmp/*" -prine -mtime +48 -print

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: find command - how to exclude subdirectories and files within subdirectories

The -path and -prune option of find is helpful in this case.

find /tmp -path "/tmp/*" -prune -mtime +48 -print

HTH

-- Rod Hills
There be dragons...
Helen French
Honored Contributor

Re: find command - how to exclude subdirectories and files within subdirectories

Try this command:

# find /tmp -prune -type f -mtime +2 -exec ll {} \; > /tmp/old_files

Also, please note that the number given with mtime is calculated in days and not hrs.
Life is a promise, fulfill it!
James R. Ferguson
Acclaimed Contributor

Re: find command - how to exclude subdirectories and files within subdirectories

Hi Paul:

First, if you really mean 2-days then the -mtime argument should be +2 not +48 :-))

Use this:

# cd /tmp
# find . -path "./*" -prune -type f -mtime +2 -exec ls -l {} \;

Regards!

...JRF...
Helen French
Honored Contributor

Re: find command - how to exclude subdirectories and files within subdirectories

A lot of other ways to do the same:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xb2f95f260cafd4118fef0090279cd0f9,00.html
Life is a promise, fulfill it!