This document provides information on the find and locate commands in Linux/Unix systems. Find searches the file system recursively to locate files and directories based on user-specified criteria like name, type, permissions, size, etc. Locate searches a database of file names and permissions that is usually updated daily. While find searches in real-time, locate searches faster but may return outdated results if the database is not recent. Both commands have options to filter results but find offers more filtering capabilities.
1. Find and Locate Utility
Pal Nikola
Praful Borad
Ravina Prajapati
2. Find:-
● Search for files in real time system.
● Find is a command for recursively filtering objects in the file
system.
● Find command used to search and locate list of files and
directories based on conditions you specify for files that
match the arguments.
● Files can be find based on the following:-
1.permissions
2.users
3.groups
4.file type
5.age
6.size
3. Switches for FIND
Switches Description
maxdepth x Search current directory as well as all sub-
directories X levels deep.
-iname Search without regard for case.
-not Return only results that do not match the
test case.
-type f Search for files.
-type d Search for directories.
-L Follow symbolic Link
-delete Immediately delete after finding the file
-exec Immediately process the file in same
command
4. Find files using name in current directory
find . -name hello.txt
find . -name test.txt
5. Find files using name and ignoring case
find /home -iname “new.txt”
6. Find files under home directory
find /home -name '*.jpg
find /home/username/ -name "*.txt“
16. Locate
Search for files and directories from existing database.
It is often used when speed is the top most priority for finding any files or
directories.
Database is renewed every 24 hours.
Locate only stores names and permissions.
17. How to get the statistic of the database
locate –S
18. Syntax and switches of locate command
Syntax :-locate [options] filename
Switches Description
-c (count) Instead of writing file names on
standard output, write the number of
matching entries only.
-e (existing) Print only entries that refer to files
existing at the time locate is run.
-i (ignore case) Ignore case while matching
-l,-n (limit) Exit successfully after finding LIMIT
entries.
-S (statistics) Write statistics about each read
database to standard output instead
of searching for files and exit
successfully.
19. To get the count of number of matching
entries
locate -c *.txt
locate -c *.mp3
locate -c hello.txt
20. Check file existence
locate -e sysctl.conf
Even when the file exist in the mlocate.db, it will still verify to make sure the
file is physically present in the system before displaying it.
23. Difference between find and locate
Find Locate
Searches in whole system and find the
specified files or directories.
Searches in database which is already
created in system.
Find command has number of options and is
very configurable.
Locate has very few options.
We can find files based on name, size,
age, permission, user, groups etc
We can find files based on name and
permission only.
There are many ways to reduce the depth
and breadth of your search and make it more
efficient.
While locate cannot be reduced to
make it efficient.
Find is more accurate as it search in
real time system.
Locate is less accurate as it searches
from the existing database because if
database is not updated then locate
command will find any match. To sync the
database, it is must to execute the
“updatedb” command.
24. Difference between find and locate
Find Locate
If a file is deleted then find command
will not give the match as it searches
in real time system.
If a file is deleted still locate command
will show the matched file if the file
image still exist in the database.
Find is slow. Locate is fast.