LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-06-2007, 06:50 PM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
Searching For Files


I find searching for files in Linux very annoying. It usually never find what I am looking for even when I have the exact file name. I decided to test this today and the only one that seems to work is "locate" even though I constantly "updatedb" before performing a search.

Here is an example. Am I using the wrong search commands or are they being used incorrectly?

Code:
cwilliams:/# whereis holland2
holland2:
cwilliams:/# whereis back.jpg
back:
cwilliams:/# find back.jpg
find: back.jpg: No such file or directory
cwilliams:/# locate back.jpg
/home/carlos/back.jpg
 
Old 01-06-2007, 07:12 PM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Code:
$ whereis whereis
whereis: /usr/bin/whereis /usr/X11R6/bin/whereis /usr/bin/X11/whereis /usr/share/man/man1/whereis.1.gz
whereis only looks in the standard locations for binary and manual files. It won't find anything else. Locate (slocate) keeps a catalogue of every file in your system ...
Code:
$ whereis kiaora
kiaora:
$ locate kiaora
/home/simon/projects/isos/kiaora-008.iso
The "apropos" command searches manual page descriptions for a search term. So it won't find things that do not have a man page.
Code:
$ apropos kiaora
kiaora: nothing appropriate.
$ apropos whereis
whereis (1)          - locate the binary, source, and manual page files for a command
$ apropos apropos
apropos (1)          - search the manual page names and descriptions
$ apropos locate | grep GNU
locate (1)           - Security Enhanced version of the GNU Locate
slocate (1)          - Security Enhanced version of the GNU Locate
$ apropos find | grep files
find (1)             - search for files in a directory hierarchy
findfs (8)           - Find a filesystem by label or UUID
texfind (1)          - graphical tool to search for text in TeX input files
To find out what things do - type "info <command>" or "man <command>".

slocate is probably the most likely to find things - but it will find alot of things (eg: locate mozilla produces 1211 lines of output!) so it gets used with "grep" a lot.

Last edited by Simon Bridge; 01-06-2007 at 07:21 PM.
 
Old 01-06-2007, 07:21 PM   #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
I don't really use locate or whereis being an old UNIX hand.

Your syntax for "find" is wrong. To find a file you have to specify WHERE to search then WHAT to search for.


So instead of "find back.jpg" you should type "find / -name back.jpg".

This tells it to search all of / (which is the entire system since / is the root of all other directories) for the file named back.jpg.

find is a very powerful tool with many options. Say for example you new back.jpg was in someone's home directory. You could say "find /home -name back.jpg" That would speed up the search because it wouldn't have to search all of the other subdirectories of /.

Say you had an NFS mount or SMB mount and didn't want to search it (which you really don't unless you think its there). Assuming all of your main directories were ext3 filesystems you could say:

"find / -fstype ext3 -name back.jpg"

That would make it exclude all filesystems other than ext3.

Say you wanted to find a file that you new was in the root filesystem rather than one of the other ones (assumes you have separate mounts for the others).

"find / -name back.jpg -xdev"

That way if /home, /usr and /opt were separate mounts it wouldn't search any of those. It would also of course not search any NFS or SMB mounts as they would be separate mounts.

You can even do "or" searches by putting in "-o" flags.

Typing "man find" will give you all the details you need.
 
Old 01-06-2007, 07:28 PM   #4
xjlittle
Member
 
Registered: Aug 2003
Location: Indiana
Distribution: fc6 sles9 & 10 kubuntu ubuntu-server
Posts: 240
Blog Entries: 2

Rep: Reputation: 30
In addition to what Simon wrote the syntax for the find command is:
Code:
find <fromsomedirectory> <option> <"somename">
For example if I want to find mozilla and all iterations of mozilla under /usr/lib, I'm in my home directory and I want the search to be case insensitive:
Code:
jslittl@jslittl-laptop:~$ find /usr/lib -iname "*mozilla*"
/usr/lib/firefox/extensions/langpack-en-GB@firefox.mozilla.org
/usr/lib/python2.4/_MozillaCookieJar.py
/usr/lib/python2.4/_MozillaCookieJar.pyc
/usr/lib/mozilla
/usr/lib/mozilla-thunderbird
/usr/lib/mozilla-thunderbird/extensions/langpack-en-GB@thunderbird.mozilla.org
/usr/lib/mozilla-firefox
/usr/lib/j2se/1.4/jre/plugin/amd64/mozilla
/usr/lib/mozilla-snapshot
jslittl@jslittl-laptop:~$
Find is a very powerful command when you learn how to use it. Look at the man page
Code:
man find
hth
 
Old 01-06-2007, 10:01 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
I decided to test this today and the only one that seems to work is "locate" even though I constantly "updatedb" before performing a search.
Just want to be sure you understand that updatedb builds the index for locate (and not whereis or find). To expand upon what was already said here, whereis is used to find binaries and some of their accompanying files -- not personal files like jpegs. The find program gives you a great amount of flexibility if you can be bothered to learn the syntax. (It's worth it if you can.)

Still, locate is a quick and easy alternative, presuming you're not frequently looking for files that were created within the last few hours. Typical usage is to allow updatedb to run nightly as a cronjob so that you don't have to run it yourself. Rebuilding your index before every search completely defeats the quickness aspect of it.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
searching for files deept Programming 1 08-15-2005 11:54 AM
help searching files jorasmi Slackware 3 02-02-2005 04:06 AM
Searching files on Linux dasoslukos Linux - Software 2 10-24-2004 11:12 PM
searching for multiple files ryedunn Linux - Newbie 4 09-27-2004 03:21 PM
Searching for files in KDE 3.1? bolinux Linux - Newbie 1 10-10-2003 11:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:51 PM.

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