1.介绍
locate是一个Unix实用程序,用于快速查找文件和目录。它是find命令的一个更方便和高效的替代品,find命令搜索整个文件系统,而locate命令则查看系统中定期更新的文件数据库。因此,搜索完成得更快。
2.指令
❯ locate -h
Usage: plocate [OPTION]... PATTERN...
-b, --basename search only the file name portion of path names
-c, --count print number of matches instead of the matches
-d, --database DBPATH search for files in DBPATH
(default is /var/lib/plocate/plocate.db)
-i, --ignore-case search case-insensitively
-l, --limit LIMIT stop after LIMIT matches
-0, --null delimit matches by NUL instead of newline
-N, --literal do not quote filenames, even if printing to a tty
-r, --regexp interpret patterns as basic regexps (slow)
--regex interpret patterns as extended regexps (slow)
-w, --wholename search the entire path name (default; see -b)
--help print this help
--version print version information
3.常用指令
locate 1.txt
locate -i a.txt 忽略大小写
locate *.txt 查找以txt结尾的文件
locate -n 10 1.txt 查找1.txt文件,显示前10个
locate -r ‘1\.txt$’ 查找以1.txt结尾的文件,里面要转义