Every day a Linux command (LOACTE) command

Source: Internet
Author: User

Locate allows users to quickly search the file system for specific files.

(1) Usage:

Usage: Locate [Options] [parameters]

(2) Function:

Features: Search for entries in the Mlocate database to quickly find files or directories

(3) Option parameters:

1)-d< catalogue > or--database=< directory;: Specify the directory where the database resides

2)-I,--ignore-case match mode when ignoring case differences

3)--help: Display Help

4)--version: Display version information

5)-D,--database DBPATH replaces the default database (/var/lib/mlocate/mlocate.db) with DBPATH

(4) Example:

1) [[email protected] documents]# loacte less1 Find this file or folder named Less1 in each directory

[[email protected] documents]# ll total dosage --rw-r--r--.1Root root664May9  -: -Head_text-rw-r--r--.1Root root $May9  ,: theLess1-rw-r--r--.1Root root $May9  ,: -Less2-rw-r--r--.1Root root259May A  +: -Tail_text-rw-r--r--.1Root root216May A  A: -Tempory[[email protected] documents]# slocate LESS1//Proven, no slocate this command bash:s Locate: Command not found ... Similar commands are:'Locate'[[email protected] documents]# loacte less1bash:loacte: Command not found ... Similar commands are:'Locate'

2) [[email protected] documents]# Locate documents If you are searching for a folder name, the folder and the following files and folders are displayed by default.

[email protected] documents]# Locate Documents/home/sunjimeng/Documents/home/sunjimeng/documents/Head_text/home/sunjimeng/documents/Less1/home/sunjimeng/documents/Less2/home/sunjimeng/documents/Tail_text/home/sunjimeng/documents/tempory/usr/share/dbus-1/services/Org.gnome.Documents.GDataMiner.service/usr/share/dbus-1/services/Org.gnome.Documents.SearchProvider.service/usr/share/dbus-1/services/Org.gnome.Documents.ZpjMiner.service/usr/share/glib-2.0/schemas/org.gnome.documents.enums.xml

3) [[Email protected] documents]# Locate newlocate and UpdateDB to prevent new folders from being found, you can update the database immediately (updatedb command)

[[ Email protected] documents]# Touch newlocate//new file [[email protected] documents]# LL Total usage already exists --rw-r--r--.1Root root664May9  -: -Head_text-rw-r--r--.1Root root $May9  ,: theLess1-rw-r--r--.1Root root $May9  ,: -Less2-rw-r--r--.1Root root0May the  -: +newlocate-rw-r--r--.1Root root259May A  +: -Tail_text-rw-r--r--.1Root root216May A  A: -Tempory[[email protected] documents]# locate Newlocate//But could not find [[email protected] documents]# UpdateDB//Update database [[email protected] documents]# Locate Newlocate//After the computer reacts for 2 seconds, then execute the locate command, We can find it./home/sunjimeng/documents/newlocate

4) Find a file in the specified directory, or you can use a wildcard character

[Email protected]/]# locate/home/sunjimeng/documents/*e/home/sunjimeng/documents/newlocate

5) [[email protected]/]# locate-i/home/sunjimeng/documents/*cate ignore case when using wildcard characters

[Email protected]/]# locate-i/home/sunjimeng/documents/*Cate/home/sunjimeng/documents/ Newlocate[[email protected]/]# locate  /home/sunjimeng/documents/*cate[[email protected]/]# 

6) [[email protected]/]# locate/home/sunjimeng/documents/le look for files or folders that start with a specific string

[[email protected]/]# locate/home/sunjimeng/documents/le                                    //Do not add wildcards can also /home/sunjimeng/documents/  Less1/home/sunjimeng/documents//]# locate/home/sunjimeng/documents/le*                     /home/sunjimeng/ documents/less1/home/sunjimeng/documents/

7) [[Email protected] documents]# Locate--help

[Email protected] documents]# Locate--helpusage:locate [OPTION] ... [PATTERN] ... Search forEntriesincha mlocate database. -A,--All only print entries this match all patterns-B,--basename match only theBasename of path names-C,--count only print number of found entries-D,--database DBPATH use DBPATH instead ofdefaultDatabase (which is/var/lib/mlocate/mlocate.db)-E,--existing only print entries forcurrently existing Files-L,--follow follow trailing symbolic links when checking file existence (default)  -H,--help print This Help-I.,--ignore- CaseIgnore Casedistinctions when matching patterns-L,--limit,-n Limit output (or counting) to LIMIT entries-M,--mmap ignored, forBackward Compatibility-P,--nofollow,-H Don'T follow trailing symbolic links when checking fileexistence-0, --NULLseparate entries with NUL on output-S,--statistics Don'T search for entries, print statistics on eachused Database-Q,--Quiet Report No error messages about reading databases-R,--regexp regexp search forbasic regexp regexp instead of patterns--regex patterns is extended regexps-S,--stdio ignored, forBackward Compatibility-V,--version print version information-W,--wholename Match whole path name (default) Report the bug to [email protected]

(5) Other:

Description

The locate command is actually another way of find-name, but much faster than the latter because it does not search for a specific directory, but instead searches for a database/var/lib/locatedb, which contains all the local file information. The Linux system automatically creates this database and updates it automatically once a day, so you can't find the latest changed files using the Locate command. To avoid this situation, you can manually update the database by using the UpdateDB command before using locate.

The Locate command can quickly find the file when searching for a database, the database is updated by the UpdateDB program, UpdateDB is created periodically by cron Daemon, Locate command in the search database than by the entire data from the hard disk to search for data, but the worse is locate found if the file is recently established or just renamed, may not be found, in the default value, the UpdateDB will run once a day, can be modified crontab to update the set value. (Etc/crontab)

locate designated to search for eligible files, it will be stored in the file and directory name of the database, to find matching template style conditions of the file or directory, you can use special characters (such as "*" or "?" And so on) to specify the template style, as specified by Kcpa*ner, locate will find all files or directories that have a starting string of KCPA and end with NER, such as the name Kcpartner if the directory name is Kcpa_ner, all files including subdirectories in that directory will be listed .

Every day a Linux command (LOACTE) command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.