Linux下4个查找命令which、whereis、locate、find的总结
来源:互联网 发布:国家统计局 月度数据 编辑:程序博客网 时间:2024/06/17 22:51
本人是Linux的初学者,由于在使用Linux的过程中经常受到各种相似命令工具使用的困扰,遂萌生写此总结。Linux下查找相关命令主要有以下4个:which、whereis、locate、find。
(1)which [-a] cmdname1 cmdname2 ......
作用:locate a command,从环境变量PATH中,定位/返回与指定名字相匹配的可执行文件所在的路径
原理:执行which命令时,which会在当前环境变量PATH中依次寻找能够匹配所找命令名字的可执行文件名,不加-a选项,返回第一个匹配的可执行文件的路径,否则依 次返回满足条件的所有可执行文件的路径名。
适用场合:一般用于查找命令/可执行文件所在的路径。有时候可能在多个路径下存在相同的命令,该命令可用于查找当前所执行的命令到底是哪一个位置处的命令。
(2)whereis [-bmsu] filename1 filename2 .......
作用:locate the binary, source, and manual page files for a command.即:定位/返回与指定名字匹配的二进制文件、源文件和帮助手册文件所在的路径。
原理:whereis命令首先会去掉filename中的前缀空格和以.开头的任何字符,然后再在数据库(var/lib/slocate/slocate.db)中查找与上述处理后的filename相匹配的二进 制文件、源文件和帮助手册文件,使用之前可以使用updatedb命令手动更新数据库。
适用场合:二进制文件、源文件和帮助手册文件路径的查找。
(3)locate [option] filename1 filename2 ......
作用:find files by name from one or more databases prepared by updatedb. 同whereis指令一样,也是从数据库建立的索引中查找,不同的是该命令查找所有部分匹配的文件,使用之前可以使用updatedb命令手动更新数据库。
原理:默认情况下(当filename中不包含通配符*),locate会给出所有与*filename*相匹配的文件的路径。
适用场合:没有文件类型性质的模糊查找(你只记得某个文件的部分名称)。
(4)find [option] [path1 path2 ......] [filename]
参数说明:
时间查找参数:
-atime n: 将n*24小时内access过的文件列出来
-ctime n: 将n*24小时内状态发生改变的文件列出来
-mtime n: 将n*24小时内被修改过的文件列出来
-newer file: 把比file还要新的文件列出来
名称查找参数:
-gid n: 寻找群组ID为n的文件
-group name: 寻找群组名称为name的文件
-uid n: 寻找拥有者ID为n的文件
-user name: 寻找拥有者名称为name的文件
-name file: 寻找文件名为file的文件(可以使用通配符)
作用:search for files in a directory hierarchy. 从当前目录递归的搜索文件。
原理:遍历当前工作目录及其子目录,find命令是在硬盘上遍历查找,非常耗硬盘资源,查找效率相比whereis和locate较低。
适用场合:能用which、whereis和locate的时候尽量不要用find.
4个命令的比较如下表所示:
- Linux下4个查找命令which、whereis、locate、find的总结
- Linux下4个查找命令which、whereis、locate、find的区别
- linux下的文件查找命令总结:find、locate、whereis、which
- linux下查找命令which/whereis/locate/find的对比和总结
- linux中Find、whereis、locate、which查找文件命令总结
- linux中Find、whereis、locate、which查找文件命令总结
- linux查找命令which、whereis、locate、find
- Linux下which、whereis、locate、find 命令查找文件
- Linux下which、whereis、locate、find 命令查找文件
- Linux下which、whereis、locate、find 命令查找文件
- Linux下which、whereis、locate、find 命令查找文件
- Linux的五个查找命令:find,locate,whereis,which,type
- Linux的五个查找命令:find,locate,whereis,which,type
- Linux的五个查找命令:find,locate,whereis,which,type
- linux的五个查找命令find,locate,whereis,which,type
- Linux的五个查找命令:find,locate,whereis,which,type
- Linux的五个查找命令:find,locate,whereis,which,type
- Linux的查找命令find,which,whereis,locate区别
- 用Maven插件生成Mybatis代码
- BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the Applic
- CGLib动态代理原理及实现
- POJ 3304 Segments(计算几何)
- inner join、left join和right join的作用
- Linux下4个查找命令which、whereis、locate、find的总结
- Android UI 使用HTML布局(直接打开服务器网页)
- Chromium can not be run as root错误
- 数据表创建参数介绍(二) 2011-02-27 20:00:27
- Android去掉标题栏的三种方法和全屏的三种方法
- 类目,延展和协议
- C语言 两种方法求一个十进制无符号数的二进制数中1的个数
- 浅谈 js 模仿手机的 动作
- Permutation Sequence