Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Locate looks up the location of a file in a database. The database is normally updated nightly in a cron job. Newer files won't be listed. Often, locate is configured to scan system directories and not your personal files.
The find command scans directories looking for files that match the criterions you gave.
You can find files by type, size, date or name pattern. You can execute commands on the results, or print the results in different formats. You can even generate a bash script using -printf. I've done this to add " around the file names.
The info manual for find "finding files" is pretty good. I'd recommend reading through it.
Aonther difference between locate and find is, locate matches the pattern even if it is in its absolute path, which find does not do. this will greatly shortlist the results.
In simple words, locate searches for file within the system database, not personal ones
No. it will search for all files including personal ones. when you create a new file (personal) and if it is not shown in locate, then that file has not been updated in database yet. it will get updated in next boot, or you can update manually by 'updatedb' command.
What i understand is, linux uses that database to locate for files for internal use. you use 'locate' just to see files -- say, what its like through the eyes of linux. whereas 'find' is for users to search according to their convenience and needs.
I am unclear whether you looked at these threads before asking this question. In general, as well as previous threads, the man pages contain many of the answers to this type of question, although sometimes they are not the easiest of reading.
What i understand is, linux uses that database to locate for files for internal use. you use 'locate' just to see files -- say, what its like through the eyes of linux. whereas 'find' is for users to search according to their convenience and needs.
Hope i'm correct.
Sorry to say, you are not correct. Both tools are for users to locate specific or non-specific things in the filesystem. The locate/updatedb combination composes a database that can be quickly accessed to locate files and directories that match some specified pattern. It only searches a database, which makes it faster. In contrast, find does a live search of the filesystem, reporting files and directories that match a fairly complex set of possible constraints. Since it searches a live filesystem, it will not ever be out-of-date. It can also be faster, if the directory tree that it searches is small, or if the '-maxdepth' option is specified.
Neither system is used 'internally' in any rigorous sense (although there may be some use of find in system scripting). The kernel and other critical systems will be quite happy without locate. find is very much optimized to work as the engine of a filesystem traversal script. It's rich set of filtering parameters makes it well suited to composing lists of files, and its output integrates well with standard scripting idiom.
No. it will search for all files including personal ones. when you create a new file (personal) and if it is not shown in locate, then that file has not been updated in database yet. it will get updated in next boot, or you can update manually by 'updatedb' command.
What i understand is, linux uses that database to locate for files for internal use. you use 'locate' just to see files -- say, what its like through the eyes of linux. whereas 'find' is for users to search according to their convenience and needs.
Hope i'm correct.
Most often the user nobody is used to scan the filesystem. The nobody user won't have access to your home directory. You can configure locate to include your personal files where another instance of updatedb runs as your user, keeping a private database. Or you could configure updatedb to be run as root. The latter option is usually configured in an /etc/sysconfig/ file.
There are hardly any similarities between locate and find. Find is much more flexible and scans the file system. Locate simply looks up values in its database.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.