Operating System - HP-UX
1823726 Members
3639 Online
109664 Solutions
New Discussion юеВ

Find command exclude directories

 
sgreyling
Advisor

Find command exclude directories

Hi,

I'm trying to search for a file in the root directory that was created during the day. I have no idea what it is and the root filesystem is almost full.

How do I do a search only in the root directory excluding other filesystems etc: /etc /var ...

So my find command will be something like: find / -size +100 -mtime +1 ...?

Please who can help?

Schalk
12 REPLIES 12
Dennis Handly
Acclaimed Contributor

Re: Find command exclude directories

You need to add -xdev to prevent crossing to other file systems.
Davis Paul
Valued Contributor

Re: Find command exclude directories

Hi Dennis,
You may please explain bit more with your above answer ... I mean to say with one example.



sgreyling
Advisor

Re: Find command exclude directories

Thanks for the reply.

I want to exclude certain directories, for instance if I run "find / -size +100 -mtime +1 -xdev /etc -exec ls -l {} \;" I still get: two problems

1) It finds files in /etc
2) I get very old files, whats wrong with my mtime?

Regards,
SChalk
Dennis Handly
Acclaimed Contributor

Re: Find command exclude directories

>I want to exclude certain directories

It is better to grep -v the result of find if you have anything complicated.

>find / -size +100 -mtime +1 -xdev /etc -exec ls -l {} \;

-xdev doesn't take a path.
You should also replace "\;" by "+" for performance.
You'll probably want to skip directories (-type f) or you'll need to change your "ls -l" to "ll -d".

>1) It finds files in /etc

That will happen if in the same file system as /.

>2) I get very old files, whats wrong with my mtime?

+1 is older than 1 day. You want -1.

>Davis: You may please explain bit more with your above answer

Not much to explain, look at find(1). Just add -xdev before the -exec.

I've also noticed that you seem to be checking the "Retain format" box. That doesn't make it easy to follow links:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1212050
V. Nyga
Honored Contributor

Re: Find command exclude directories

Hi,

with 'man find' you would get all informations you want.
'-xdev' is a stand-alone option to aviod 'find' to search across MOUNTED file systems. So if /etc, /var is mounted, it would be excluded.
To avoid find to search through certain directories use '-prune' - check the man pages of find with the examples how to use it.

Volkmar
*** Say 'Thanks' with Kudos ***
sgreyling
Advisor

Re: Find command exclude directories

Hi Dennis,

Sorry, the command with /etc was the incorrect command I copied from my putty session. It was suppose to be without /etc

Thanks, the -1 option works.

Let me try to rephrase my question:

I want to find files everywhere under root but exclude directories /users, /etc, /var, /data ...

Hope this makes more sense.
V. Nyga
Honored Contributor

Re: Find command exclude directories

Hi again,

so test:
find / -path ./etc -prune (or /etc -prune )

V.
*** Say 'Thanks' with Kudos ***
john korterman
Honored Contributor

Re: Find command exclude directories

Hi,

try something like this:

# find / \( ! -path "/etc/*" \) -a \( ! -path "/users/*" \) -a \( ! -path "/data/*" \) -type f


regards,
John K.
it would be nice if you always got a second chance
Steve Post
Trusted Contributor

Re: Find command exclude directories

you seem to really want to exclude stuff like /etc.

I have an easy way to exclude /etc.

DONT.

Instead filter it off AFTER you got your list of files.

try this....
find / -xdev -mtime -1 -size +2000 -type f -print | grep -vE "^/etc" \ > /tmp/mybigoldfile.txt

You said the / file system is almost full. You can say you don't want to look at /etc, but I bet /etc is part of the / filesystem. So you should be looking there instead of ignoring it.

The option I really like is that -xdev. It excludes stuff that is on the filesystem you are looking at.
Dennis Handly
Acclaimed Contributor

Re: Find command exclude directories

>Steve: Instead filter it off AFTER you got your list of files.

Didn't I already say that? :-)
sachit patil
Regular Advisor

Re: Find command exclude directories

Check wheather /etc/lvmconf/vg* files
If old files are there the delete that one.
or tar the files.
Steve Post
Trusted Contributor

Re: Find command exclude directories

Dennis,
Yep. Sorry. I just didn't see it.

steve