which 命令的工作方式与 find 命令和 locate 命令有很大的区别。它使用你的搜索路径($PATH)并检查其上的每个目录中具有你要查找的文件名的可执行文件。一旦找到一个,它会停止搜索并显示该可执行文件的完整路径。
which 命令的主要优点是它回答了“如果我输入此命令,将运行什么可执行文件?”的问题。它会忽略不可执行文件,并且不会列出系统上带有该名称的所有可执行文件 —— 列出的就是它找到的第一个。如果你想查找具有某个名称的所有可执行文件,则可以像这样运行 find 命令,但是要比非常高效 which 命令用更长的时间。
$ apropos find File::IconTheme (3pm) - find icon directories File::MimeInfo::Applications (3pm) - Find programs to open a file by mimetype File::UserDirs (3pm) - find extra media and documents directories find (1) - search for files in a directory hierarchy findfs (8) - find a filesystem by label or UUID findmnt (8) - find a filesystem gst-typefind-1.0 (1) - print Media type of file ippfind (1) - find internet printing protocol printers locate (1) - find files by name mlocate (1) - find files by name pidof (8) - find the process ID of a running program. sane-find-scanner (1) - find SCSI and USB scanners and their device files systemd-delta (1) - Find overridden configuration files xdg-user-dir (1) - Find an XDG user dir $ $ apropos locate blkid (8) - locate/print block device attributes deallocvt (1) - deallocate unused virtual consoles fallocate (1) - preallocate or deallocate space to a file IO::Tty (3pm) - Low-level allocate a pseudo-Tty, import constants. locate (1) - find files by name mlocate (1) - find files by name mlocate.db (5) - a mlocate database mshowfat (1) - shows FAT clusters allocated to file ntfsfallocate (8) - preallocate space to a file on an NTFS volume systemd-sysusers (8) - Allocate system users and groups systemd-sysusers.service (8) - Allocate system users and groups updatedb (8) - update a database for mlocate updatedb.mlocate (8) - update a database for mlocate whereis (1) - locate the binary, source, and manual page files for a... which (1) - locate a command