Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Finding Files

There are two different facilities for finding files: find and locate. find searches the actual files in their present state. locate searches an index generated by the system every morning at 6:42 a.m. (this is a cron job, explained elsewhere in this book). locate won't find any files that were created after the index was generated. However, because locate searches an index, it's much faster - like using the index of a book rather than looking through the whole thing.

To compare the two ways of finding files, pretend you can't remember where the X configuration file XF86Config resides.

locate XF86Config
This should be pretty fast. You'll get a list of filenames that contain XF86Config, something like this:

/etc/X11/XF86Config

/usr/X11R6/lib/X11/XF86Config 

/usr/X11R6/lib/X11/XF86Config.eg 

/usr/X11R6/man/man5/XF86Config.5x.gz 

Now try the find command:

find / -name XF86Config
You will hear a lot of disk activity, and this will take a lot longer. Results will look something like this:

/etc/X11/XF86Config

/usr/X11R6/lib/X11/XF86Config

find: /var/spool/cron/atjobs: Permission denied

find: /var/spool/cron/atspool: Permission denied

find: /var/lib/xdm/authdir: Permission denied

Notice that find found only files that were named exactly XF86Config, rather than any files containing that string of letters. Also, find actually tried to look in every directory on the system - including some where you didn't have read permissions. That's why you got the Permission denied messages.

The syntax is different as well. With find, you had to specify what directory to search in, whereas locate automatically chose the root directory. And you had to specify a search by name using the -name option. You could also have searched for files using many other criteria, such as modification date or owner. To have find search for files whose names match XF86Config, you'd have to use a wildcard:

find / -name '*XF86Config*'
Like most of the command line tools, find accepts wildcards as arguments.

In general, find is a more powerful utility, and locate is faster for everyday quick searches. The full range of possible searches would take a long time to explain; for more details , type info find, which will bring up the very thorough info pages on find and locate.

John Goerzen / Ossama Othman

 
 
  Published under the terms of the GNU General Public License Design by Interspire