🖥️locate
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the locate command with important options and switches using examples.
4 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██╗ ██████╗ ██████╗ █████╗ ████████╗███████╗
# ██║ ██╔═══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝
# ██║ ██║ ██║██║ ███████║ ██║ █████╗
# ██║ ██║ ██║██║ ██╔══██║ ██║ ██╔══╝
# ███████╗╚██████╔╝╚██████╗██║ ██║ ██║ ███████╗
# ╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝
# The locate command helps user find a file by name.
locate [file-name]
locate --regex '\.c$' | shuf | head -1 | xargs pv -q -L 20
# Poor man's hacker typer in the terminal.
# Useful ‘locate’ Command Practical Examples for Linux Newbies
###################################################################
# Limit Search Queries to a Specific Number - You can limit your search returns to a required number to avoid redundancy with your search results using the -n command. For example, if you want just 20 results from your queries, you can type the following command:
locate "*.html" -n 20
# Display The Number of Matching Entries
# If you want to display the count of all matching entries of file “tecmint“, use the locate -c command.
locate -c [tecmint]*
1550
# Ignore Case Sensitive Locate Outputs
# By default, locate is configured to process queries in a case sensitive manner meaning TEXT.TXT will point you to a different result than text.txt. To have locate command ignore case sensitivity and show results for both uppercase and lowercase queries, input commands with the -i option.
locate -i *text.txt*
/home/tecmint/TEXT.txt
/home/tecmint/text.txt
# Refresh mlocate Database
# Since locate command relies on a database called mlocate. The said database needs to be updated regularly for the command utility to work efficiently. To update the mlocate database, you use a utility called updatedb. It should be noted that you will need superuser privileges for this to work properly, is it needs to be executed as root or sudo privileges.
updatedb
# Display Only Files Present in Your System
# When you have an updated mlocate database**, locate command still produces results of files whose physical copies are deleted from your system. To avoid seeing results of files not present in your machine at the time of punching in the command, you will need to use the locate-e command. The process searches your system to verify the existence of the file you’re looking for even if it is still present in your mlocate.db.
locate -i -e *text.txt*
/home/tecmint/text.txt
# Separate Output Entries Without New Line
# locate command’s default separator is the newline (\\n) character. But if you prefer to use a different separator like the ASCII NUL, you can do so using the -0 command line option.
locate -i -0 *text.txt*
/home/tecmint/TEXT.txt/home/tecmint/text.txt
# Review Your Locate Database
# If you’re in doubt as to the current status of your mlocate.db, you can easily view the locate database statistics by using the -S command.
locate -S
Database /var/lib/mlocate/mlocate.db:
32,246 directories
4,18,850 files
2,92,36,692 bytes in file names
1,13,64,319 bytes used to store database
# Suppress Error Messages in Locate
# Constantly trying to access your locate database does sometimes yield unnecessary error messages stating that you do not have the required privileges to have root access to the mlocate.db, because you’re only a normal user and not the required Superuser. To completely do away with these message, use the -q command.
locate "\*.dat" -q*
# Choose a Different mlocate Location
# If you’re inputting queries looking for results not present in the default mlocate database and want answers from a different mlocate.db located somewhere else in your system, you can point the locate command to a different mlocate database at a different part of your system with the -d command.
locate -d <new db path> <filename>
#==============================##==============================#
# CMD LOCATE #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command locate in a clear format. This allows users to quickly access the needed information for locate without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for locate are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.