Linux which/whereis/locate命令详解

时间:2021-11-24 10:56:41

which 查看可执行文件的位置,从全局环境变量PATH里面查找对应的路径,默认是找 bash内所规范的目录

whereis 查看文件的位置,配合参数-b,用于程序名的搜索,从linux数据库查找。

locate 配合数据库查看文件位置。

find 实际搜寻硬盘查询文件名称,效率低。

which常用命令参数

--version, -[vV] Print version and exit successfully.
--help, Print this help and exit successfully.
--skip-dot Skip directories in PATH that start with a dot.
--skip-tilde Skip directories in PATH that start with a tilde.
--show-dot Don't expand a dot to current directory in output.
--show-tilde Output a tilde for HOME directory for non-root.
--tty-only Stop processing options on the right if not on tty.
--all, -a Print all matches in PATH, not just the first
--read-alias, -i Read list of aliases from stdin.
--skip-alias Ignore option --read-alias; don't read stdin.
--read-functions Read shell functions from stdin.
--skip-functions Ignore option --read-functions; don't read stdin.

which常用的命令展示

which cp  ==> /bin/cp

Linux which/whereis/locate命令详解

whereis常用命令参数

# Usage:  whereis [ -sbmu ] [ -SBM dir ... -f ] name...

whereis  -b  cp    ==>which cp  ==> /bin/cp

Linux which/whereis/locate命令详解

locate常用命令参数

Usage: locate [OPTION]... [PATTERN]...
Search for entries in a mlocate database. -b, --basename match only the base name of path names
-c, --count only print number of found entries
-d, --database DBPATH use DBPATH instead of default database (which is
/var/lib/mlocate/mlocate.db)
-e, --existing only print entries for currently existing files
-L, --follow follow trailing symbolic links when checking file
existence (default)
-h, --help print this help
-i, --ignore-case ignore case distinctions when matching patterns
-l, --limit, -n LIMIT limit output (or counting) to LIMIT entries
-m, --mmap ignored, for backward compatibility
-P, --nofollow, -H don't follow trailing symbolic links when checking file
existence
-0, --null separate entries with NUL on output
-S, --statistics don't search for entries, print statistics about each
used database
-q, --quiet report no error messages about reading databases
-r, --regexp REGEXP search for basic regexp REGEXP instead of patterns
--regex patterns are extended regexps
-s, --stdio ignored, for backward compatibility
-V, --version print version information
-w, --wholename match whole path name (default)

locate常用的命令展示

locate cp   ==> which cp  ==> /bin/cp

Linux which/whereis/locate命令详解