Linux下定位命令总结

1 whereis :显示指令的二进制程序、源代码文件和man手册的路径

查找所有信息

~$ whereis emacs
emacs: /usr/bin/emacs /etc/emacs
/usr/lib/emacs /usr/bin/X11/emacs
/usr/share/emacs /usr/share/man/man1/emacs.1.gz

仅查找二进制程序

~$ whereis -b emacs
emacs: /usr/bin/emacs /etc/emacs
/usr/lib/emacs /usr/bin/X11/emacs /usr/share/emacs

仅查找源代码文件

~$ whereis -s emacs
emacs:

仅查找man手册页

~$ whereis -m emacs
emacs: /usr/share/man/man1/emacs.1.gz

2 which : 仅显示指令的绝对路径

和whereis不同的是,which只能显示指令的绝对路径。

~$ which emacs
/usr/bin/emacs

3 locate/slocate :快速定位文件的路径

locate指令利用事先建立的系统中左右文件名称及路径的数据库,从而实现快速定位。如果该数据库比较陈旧,使用updatedb即可更新。和whereis以及which相比,locate可以查找普通文件,只要是带有搜索关键字的都会输出,因此内容会比较多。

输出符合条件的文件总数

~$ locate -c emacs
3737

输出所有匹配条目

~$ locate emacs
/usr/share/emacs23/site-lisp/flim/mmgeneric.elc
/usr/share/emacs23/site-lisp/flim/ntlm.el
/usr/share/emacs23/site-lisp/flim/ntlm.elc
/usr/share/emacs23/site-lisp/flim/qmtp.el
/usr/share/emacs23/site-lisp/flim/qmtp.elc
/usr/share/emacs23/site-lisp/flim/sasl-cram.el
/usr/share/emacs23/site-lisp/flim/sasl-cram.elc
/usr/share/emacs23/site-lisp/flim/sasl-digest.el
/usr/share/emacs23/site-lisp/flim/sasl-digest.elc
/usr/share/emacs23/site-lisp/flim/sasl-ntlm.el
/usr/share/emacs23/site-lisp/flim/sasl-ntlm.elc
/usr/share/emacs23/site-lisp/flim/sasl-scram.el
/usr/share/emacs23/site-lisp/flim/sasl-scram.elc
/usr/share/emacs23/site-lisp/flim/sasl.el
/usr/share/emacs23/site-lisp/flim/sasl.elc
/usr/share/emacs23/site-lisp/flim/sha1-dl.el
/usr/share/emacs23/site-lisp/flim/sha1-dl.elc
/usr/share/emacs23/site-lisp/flim/sha1-el.el
/usr/share/emacs23/site-lisp/flim/sha1-el.elc
/usr/share/emacs23/site-lisp/flim/sha1.el
/usr/share/emacs23/site-lisp/flim/sha1.elc
/usr/share/emacs23/site-lisp/w3m/shimbun/sb-atmarkit.el
/usr/share/emacs23/site-lisp/w3m/shimbun/sb-atmarkit.elc

........

/var/lib/dpkg/info/emacsen-common.list
/var/lib/dpkg/info/emacsen-common.postinst
/var/lib/dpkg/info/emacsen-common.postrm
/var/lib/dpkg/info/emacsen-common.prerm
/var/lib/emacsen-common/installed-flavors

相关推荐