public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
* Locate Vs Find
@ 2004-11-22 16:52 Ankit Jain
  2004-11-23  4:43 ` Jagadeesh Bhaskar P
  2004-12-02  5:07 ` Stephen Samuel
  0 siblings, 2 replies; 5+ messages in thread
From: Ankit Jain @ 2004-11-22 16:52 UTC (permalink / raw)
  To: newbie

Which is more efficient? /if both perform the same
work and are not different then why shoudl we have 2 ?

thanks

ankit jain

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" 
your friends today! Download Messenger Now 
http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Locate Vs Find
  2004-11-22 16:52 Locate Vs Find Ankit Jain
@ 2004-11-23  4:43 ` Jagadeesh Bhaskar P
  2004-11-25 21:00   ` lindax newbie
  2004-12-02  5:07 ` Stephen Samuel
  1 sibling, 1 reply; 5+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-11-23  4:43 UTC (permalink / raw)
  To: Ankit Jain; +Cc: Linux Newbie

On Mon, 2004-11-22 at 22:22, Ankit Jain wrote:
> Which is more efficient? /if both perform the same
> work and are not different then why shoudl we have 2 ?

As far as I know, locate is based on a database storing locations of
file. It doesnot search physically throughout the directory hierarchy.
So it is many a time faster. But you have to update the database
periodically with an "updatedb" command. Otherwise even error locations
may be the result.

Find doesnt depend on any such databases. It searches throughout the
directory hierarchy. This case results are always more reliable, but
mostly slow. 

It can be seen by "finding" a file from the "/" and "locating" the same.

I think that trade-off enough a reason!!

-- 
With regards,

Jagadeesh Bhaskar P
R&D Engineer
HCL Infosystems Ltd
Pondicherry
INDIA

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Locate Vs Find
  2004-11-23  4:43 ` Jagadeesh Bhaskar P
@ 2004-11-25 21:00   ` lindax newbie
  2004-11-28 14:13     ` J.
  0 siblings, 1 reply; 5+ messages in thread
From: lindax newbie @ 2004-11-25 21:00 UTC (permalink / raw)
  To: Jagadeesh Bhaskar P; +Cc: Ankit Jain, Linux Newbie

If you look at the 'updatedb' script, you'll even find that it uses
the 'find' command to build the static database.  Normally the database
is rebuilt only once per/day -- in the wee hours of the morning if
your computer is on then otherwise, it'll run soon after you turn it
on in the morning (in the default configuration).  As Jagadeesh says,
locate is much faster -- basically being a "grep" through a large text
database, but it doesn't contain all the same info as 'find' can access
and is only up-to-date from when it was last run...

linda

Jagadeesh Bhaskar P wrote:

>On Mon, 2004-11-22 at 22:22, Ankit Jain wrote:
>  
>
>>Which is more efficient? /if both perform the same
>>work and are not different then why shoudl we have 2 ?
>>    
>>
>
>As far as I know, locate is based on a database storing locations of
>file. It doesnot search physically throughout the directory hierarchy.
>So it is many a time faster. But you have to update the database
>periodically with an "updatedb" command. Otherwise even error locations
>may be the result.
>
>Find doesnt depend on any such databases. It searches throughout the
>directory hierarchy. This case results are always more reliable, but
>mostly slow. 
>
>It can be seen by "finding" a file from the "/" and "locating" the same.
>
>I think that trade-off enough a reason!!
>
>  
>
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Locate Vs Find
  2004-11-25 21:00   ` lindax newbie
@ 2004-11-28 14:13     ` J.
  0 siblings, 0 replies; 5+ messages in thread
From: J. @ 2004-11-28 14:13 UTC (permalink / raw)
  To: Linux Newbie

Sunday, November 28 14:38:06

> On Mon, 2004-11-22 at 22:22, Ankit Jain wrote:
>
> Which is more efficient? /if both perform the same
> work and are not different then why shoudl we have 2 ?

That's not true, they do not preform the same task.
`find' doesn't find files, it's just a side effect of
the program. `Find's' real occupation is to evaluate files.
a.k.a. to preform tests on them. For example:
find / -atime +1 -fstype ext2 -name core -exec rm '{}' \;
find . \( -fstype nfs -prune\) -o \
       \( -type d -a -exec chmod 771 '{}' \; \) -o \
       \( -name "*.BAK" -a -exec /bin/rm '{}' \; \) -o \
       \( -name "*.sh" -a -exec chmod 755 '{}' \; \)
find /home -xdev -size +500k -ls > blabla
find /usr/include -xtype f -exec grep foobar \ 
     /dev/null '{}' \;
Find recurses down a structure and preforms a stat() system call for each
regular file it encounters.. I advise you to read man page or stat(),
lstat(), readdir and the dirent.h header file..

`Locate's' only purpose is to find files. It builds a database of all
files which then later on can be searched..

There are no. examples of c code directory handeling available in the
snippits section at rdrs.net or more `find' examples in 
http://www.rdrs.net/docs/src/reminder.txt

Greetzz.. 

J.

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Locate Vs Find
  2004-11-22 16:52 Locate Vs Find Ankit Jain
  2004-11-23  4:43 ` Jagadeesh Bhaskar P
@ 2004-12-02  5:07 ` Stephen Samuel
  1 sibling, 0 replies; 5+ messages in thread
From: Stephen Samuel @ 2004-12-02  5:07 UTC (permalink / raw)
  To: Ankit Jain; +Cc: newbie

Locate only finds files by looking up the name in a database.
Once a day it regenerates the database.

If you're just looking for a filename, and you don't mind it being
anywhere up to 24 hours old (sometimes more, but rarely), then
ocate is a FAR faster way to do things.


Find, on the other hand can do WAY more tests than just
the filename, and it can do way more things with a file it
finds than just print it.   The find command syntax is
actually a primative programming language. and you can
take actions based on the file type file syatem type
mtime, ctime atime  file size, owner etc. etc.

Most, recent, versions of find can even tar up certain
matched files.

'Man find` for nore info on what find is capable of.


Ankit Jain wrote:
> Which is more efficient? /if both perform the same
> work and are not different then why shoudl we have 2 ?

-- 
Stephen Samuel +1(604)876-0426                samuel@bcgreen.com
		   http://www.bcgreen.com/~samuel/
    Powerful committed communication. Transformation touching
      the jewel within each person and bringing it to light.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-12-02  5:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-22 16:52 Locate Vs Find Ankit Jain
2004-11-23  4:43 ` Jagadeesh Bhaskar P
2004-11-25 21:00   ` lindax newbie
2004-11-28 14:13     ` J.
2004-12-02  5:07 ` Stephen Samuel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox