← 返回命令列表

Linux command

locate 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Find

locate "[pattern]"

Example

locate -i "[pattern]"

Example

locate -b "\[filename]"

Limit

locate -l [10] "[pattern]"

Count

locate -c "[pattern]"

Display

locate -S

Update

sudo updatedb

说明

locate searches a prebuilt database to find files matching a pattern, making it much faster than find for simple filename searches. The database is typically updated daily by a cron job.

参数

-i, --ignore-case
Case-insensitive search
-l, --limit N
Limit output to N entries
-c, --count
Print count of matches
-e, --existing
Only print existing files
-b, --basename
Match only basename
-r, --regexp
Use basic regex pattern
--regex
Use extended regex pattern
-d, --database _DBPATH_
Search in specified database instead of the default
-S, --statistics
Print statistics about each database and exit
-w, --wholename
Match against the whole path name (default behavior)

FAQ

What is the locate command used for?

locate searches a prebuilt database to find files matching a pattern, making it much faster than find for simple filename searches. The database is typically updated daily by a cron job.

How do I run a basic locate example?

Run `locate "[pattern]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --ignore-case do in locate?

Case-insensitive search