Linux下which、whereis、locate、find命令的区别

  • which

which是通过 PATH环境变量 到该路径内查找可执行文件

  • whereis

whereis.c的源码,在缺省的情况下,会找当前和以下的路径

static char *bindirs[] = {
“/bin”,
“/usr/bin”,
“/sbin”,
“/usr/sbin”,
“/etc”,
“/usr/etc”,
“/lib”,
“/usr/lib”,
“/lib64”,
“/usr/lib64”,
“/usr/games”,
“/usr/games/bin”,
“/usr/games/lib”,
“/usr/emacs/etc”,
“/usr/lib/emacs/*/etc”,
“/usr/TeX/bin”,
“/usr/tex/bin”,
“/usr/interviews/bin/LINUX”,

“/usr/X11R6/bin”,
“/usr/X386/bin”,
“/usr/bin/X11”,
“/usr/X11/bin”,
“/usr/X11R5/bin”,

“/usr/local/bin”,
“/usr/local/sbin”,
“/usr/local/etc”,
“/usr/local/lib”,
“/usr/local/games”,
“/usr/local/games/bin”,
“/usr/local/emacs/etc”,
“/usr/local/TeX/bin”,
“/usr/local/tex/bin”,
“/usr/local/bin/X11”,

“/usr/contrib”,
“/usr/hosts”,
“/usr/include”,

“/usr/g++-include”,

“/usr/ucb”,
“/usr/old”,
“/usr/new”,
“/usr/local”,
“/usr/libexec”,
“/usr/share”,

“/opt/*/bin”,

0
};

static char *mandirs[] = {
“/usr/man/*”,
“/usr/share/man/*”,
“/usr/X386/man/*”,
“/usr/X11/man/*”,
“/usr/TeX/man/*”,
“/usr/interviews/man/mann”,
0
};

static char *srcdirs[]  = {
“/usr/src/*”,
“/usr/src/lib/libc/*”,
“/usr/src/lib/libc/net/*”,
“/usr/src/ucb/pascal”,
“/usr/src/ucb/pascal/utilities”,
“/usr/src/undoc”,
0
};

  • locate

使用自己的一个数据库,使用updatedb来更新文件系统,会有时效性问题。

  • find

搜寻实时硬盘文件名称 (find也可以根据文件大小-size 时间-atime 正则表达式-regex)

此条目发表在服务器分类目录,贴了标签。将固定链接加入收藏夹。

发表回复