Jump to content

using find - need to exclude a directory


Recommended Posts

Posted

I want to find all occurrences of a particular file on a Linux machine but I don't want to search a particular folder tree (it's huge and I know the file isn't there - I'm looking for float.h files)

 

I can do:

find / -name "float.h"

and it works but it takes a very long time.

 

I could use:

locate float.h | grep \/float.h$

and this works except that I know the machines being used for this don't have an up-to-date database for locate (don't ask ...) so this won't work.

 

What I think I need to use is -prune in the find command but I can't work out how to do it.

 

find / -name float.h -prune -o -path '/home'

looks like it's working but it isn't because if I do

find / -name float.h -prune -o -path '/home' 2> /dev/nul

so that it throws away all the errors then I can see it's listing files in the /home tree.

 

In case anyone's wondering, this is a teaching exercise - the students have been told to find all the C compilers on the Linux VMs. I know the answer (I put them there!) but they've been told that each compiler will have a set of header files including float.h. What appears to a bug in VMWare Player means that if they scan the entire filesystem (including several directories which are actually NFS mounts) the VM grinds to a halt and takes out the Windows network stack on the host machine!

Posted

OS is RHEL 5.6; kernel is 2.6.18 and accessing it just using the normal console.

 

Is find that much different across Linux versions?? I can find man pages from 15 years ago which look pretty much like the current one!

Posted
OS is RHEL 5.6; kernel is 2.6.18 and accessing it just using the normal console.

 

Is find that much different across Linux versions?? I can find man pages from 15 years ago which look pretty much like the current one!

 

To be honest i don't have a clue, im sure that some commands i have been able to use on one distro are not usable on another, so its nice to know what type of enviroment your in. I will have a play on my live distro's this weekend and get back to you ^_^

Posted (edited)

Does this work ?

 

Not sure which directory you want to exclude, below will search everything but exclude results from /home.

 

find / -path /home -prune -o -name float.h -print

Andy

Edited by apaton
added code tags and description
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...