LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2012, 08:46 AM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
How to use find command to locate files


Hi all,

I am trying to find a file and if i use below command, looks like it searching on all the partitions that are mounted under "/" and as the all large nfs shares are mounted under this "/", it is taking too long to get the results.

Code:
find / -name text
How can i search only on partitions of the hard disk (like var, opt, usr and so on) and ignoring the nfs or any other external filesystems mounted.

Thanks in advance!
 
Old 03-30-2012, 08:48 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Just put the path you want to search in the command
Code:
find /var -name text
You can also put multiple paths in the command
Code:
 find /var /opt /usr -name text
 
1 members found this post helpful.
Old 03-30-2012, 08:53 AM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
On UNIX/Linux most commands have a manual (man) page. On Linux many commands also have an info page.

You can learn a lot by typing "man <command>" for any command you're trying to grok.

"man find" will show you details of the find command.

A key option in find is "-xdev". This tells it NOT to traverse any mount points so would exclude NFS mounts as you asked.

find /var -name text -xdev

Note that you can also use regular expressions (regexp) for "text" but have to encapulate it in quotes. So for example if you wanted to find any file that had billybob as part of the name you'd type:
find /var -name "*billybob*" -xdev
That would find files such as:
Ihatebillybob
billybobsux
whoisbillybobandwhyshouldicare
 
1 members found this post helpful.
Old 03-30-2012, 09:40 AM   #4
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi weibullguy and MensaWater,

Thank you both for great tips and suggestions.
 
Old 03-30-2012, 10:00 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Here are a couple of good links for you about how to use find:

http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between find and locate command sandeep002gupta Linux - Desktop 1 05-09-2011 04:16 AM
cpan> locate -u Unknown shell command 'locate -u'. Type ? for help. sharad2005 Linux From Scratch 1 08-04-2006 12:40 AM
Wat is main difference between find and locate command. rktech83 Linux - General 1 03-08-2006 07:38 AM
Using FIND to locate files created between certain dates billybobjoe1984 Programming 6 07-23-2005 06:07 PM
locate command shows some files which are not listed by ls .... m_a Linux - Newbie 2 08-03-2003 07:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration