Searching files manually may become hectic when you have a large collection of files in your system. In this case, you will require assistance that can bring you the search within a few seconds, irrespective of the disc usage.
In Linux, the locate command backs you up. In this article, we will be discussing various options related to the locate command in Linux.
What is the locate Command in Linux?
Searching for files and directories is one of the most typical tasks while dealing with Linux. On Linux systems, you may search for files using a variety of commands, the most common of which are find and locate. Because it searches a database instead of the file system when a file search is begun, the locate tool is better and quicker than the find command equivalent. This database stores bits and pieces of files, as well as the routes to them on your system.
By default, the locate command does not verify that the files identified in the database are still present, and it never reports files generated after the most recent database update. The syntax is:
$ locate [OPTION]... PATTERN…
1. -h, –help
To standard output, write a summary of the available options and leave successfully.
2. -b, –basename
The reverse of –wholename is to match only the base name against the supplied patterns.
3. -e, –existing
Only items that relate to files that exist at the moment locate is run are printed.
4. -c, –count
Instead of file names, merely write the number of matched entries on standard output.
5. -d, –database DBPATH
DBPATH should be used instead of the default database. DBPATH is a list of database file names separated by colons. The resultant route is a concatenation of the distinct paths if more than one –database option is supplied. The default database replaces an empty database file name. The standard input is referred to by the database file name. It's worth noting that a database can only be read from standard input once.
6. -L, –follow
Follow trailing symbolic links when verifying whether files exist (if the –existing option is supplied). Broken symbolic links are excluded from the output as a result of this. The default practice is to use this option. –nofollow can be used to specify the opposite.
7. -i, –ignore-case
When matching patterns, disregard case differences.
8. -m, –mmap
Ignored, but included for BSD and GNU locate compatibility.
9. -P, –nofollow, -H
If the –existing option is provided, do not follow trailing symbolic links while verifying if files exist. As a result, broken symbolic links are reported in the same way as other files. This is the complete opposite of –follow.
10. -l, –limit, -n LIMIT
After finding LIMIT entries, successfully exit. The resultant count is also restricted to LIMIT if the –count option is used.
11. -0, –null
Instead of putting each element on a different line, use the ASCII NUL character to separate the entries on the output. This option was created to be compatible with GNU xargs' –null option.
12. -S, –statistics
Write statistics about each read database to standard output instead of searching for files and exiting successfully.
13. -q, –quiet
Errors found when reading and processing databases should not be reported.
All patterns should be interpreted as expanded regexps.
15. -r, –regexp REGEXP
Look for REGEXP, which is a simple regex. If this option is utilized, no patterns are permitted, although this option can be used numerous times.
16. -s, –stdio
Ignored for BSD and GNU locate compatibility.
17. -V, –version
Write information about the version and license of locate on standard output and exit successfully.
18. -w, –wholename
Only the entire route name is matched against the provided patterns. The default practice is to use this option. –basename can be used to specify the reverse.
In this article, we went through various options related to the locate command in Linux. This is a powerful command which can locate the destination files very fast. Using this command, we can perform tasks like absolute file search, regex, or pattern-based search, count the number of entries, etc.
People are also reading:
Leave a Comment on this Post