+ Post New Thread
Results 1 to 6 of 6
*nix Thread, using find - need to exclude a directory in Technical; I want to find all occurrences of a particular file on a Linux machine but I don't want to search ...
  1. #1

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,159
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    125

    using find - need to exclude a directory

    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:
    Code:
    find / -name "float.h"
    and it works but it takes a very long time.

    I could use:
    Code:
    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.

    Code:
    find / -name float.h -prune -o -path '/home'
    looks like it's working but it isn't because if I do
    Code:
    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!

  2. #2

    Join Date
    May 2010
    Location
    England
    Posts
    118
    Thank Post
    21
    Thanked 20 Times in 17 Posts
    Rep Power
    13
    Can you provide more info on the OS your running, kernel version, and terminal software your running please?

  3. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,159
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    125
    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!

  4. #4

    Join Date
    May 2010
    Location
    England
    Posts
    118
    Thank Post
    21
    Thanked 20 Times in 17 Posts
    Rep Power
    13
    Quote Originally Posted by srochford View Post
    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 ^_^

  5. #5
    apaton's Avatar
    Join Date
    Jun 2009
    Location
    Kings Norton
    Posts
    283
    Thank Post
    54
    Thanked 106 Times in 87 Posts
    Rep Power
    37
    Does this work ?

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

    Code:
    find / -path /home -prune -o -name float.h -print
    Andy
    Last edited by apaton; 30th January 2011 at 08:25 PM. Reason: added code tags and description

  6. Thanks to apaton from:

    koryo (30th January 2011)

  7. #6

    Join Date
    May 2010
    Location
    England
    Posts
    118
    Thank Post
    21
    Thanked 20 Times in 17 Posts
    Rep Power
    13
    Nice one apaton, i second the above statement, thats worked great on my test computer as well.



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 1
    Last Post: 19th August 2010, 10:51 AM
  2. Replies: 4
    Last Post: 14th July 2010, 04:16 PM
  3. Find the location of a user account in Active Directory
    By FN-GM in forum Wiki Announcements
    Replies: 0
    Last Post: 27th March 2008, 12:58 AM
  4. What do you exclude from antivirus scans?
    By zag in forum How do you do....it?
    Replies: 7
    Last Post: 8th February 2008, 08:09 PM
  5. Redirection or Exclude from Profile?
    By TechSupp in forum Wireless Networks
    Replies: 2
    Last Post: 21st September 2007, 02:07 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •