Locate Vs Find
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 2 lines · Ankit Jain
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!!
Signature · 13 lines
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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs
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
Quoted 14 lines · Jagadeesh Bhaskar P
Quoted 4 lines · Ankit Jain
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.
Quoted 10 lines
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Sunday, November 28 14:38:06
Quoted 4 lines · Ankit Jain
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
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.
Quoted 2 lines · Ankit Jain
Which is more efficient? /if both perform the same work and are not different then why shoudl we have 2 ?
Signature · 9 lines
Stephen Samuel +1(604)876-0426 [email protected] 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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs