查找文件which locate find
(1)which:查找命令文件路径
which ls //命令的路径查找是根据PATH环境变量
whereis ls
echo $PATH //打印PATH环境变量
(2)locate:查找任意文件
locate查找文件是查询数据库:/var/lib/mlocate/mlocate.db
计划任务:每天自动更新数据库,/etc/cron.daily/mlocate.cron
手工更新数据库:updatedb
安装:yum provides locate //查找locate命令是哪个rpm包提供的
yum install mlocate-0.26-8.el7.x86_64 -y
locate ifcfg-eth0
(3)find:查找任意文件,牛逼工具
语法:find [options] [path...] [expression] [action]
1)根据文件名查找
find /etc -name "ifcfg-ens33" // etc目录下查找文件ifcfg-ens33
find /etc ! -name "ifcfg-ens33" //取反,etc目录下查找文件不是ifcfg-ens33的文件,
find /etc -iname "ifcfg-ens33" //-i:忽略大小写
find /etc -iname "ifcfg-ens*" //使用通配符,*任意字符
2)根据文件大写查找
find /etc/ -size +5M //etc目录下查找大于5M的文件
find /etc/ -size 5M //etc目录下查找等于5M的文件
find /etc/ -size -5M //etc目录下查找小于5M的文件
find /etc/ -size +5M -ls //etc目录下查找大于5M的文件,-ls是找到后的处理动作,不是ls命令
3)指定查找的目录深度
-maxdepth levels
-mindepth levels
find / -maxdepth 4 -a -name "ifcfg-*" //目录深度4级下查找ifcfg-开头的文件,-a表示与,
4)按时间查找(atime,ctime,mtime)
find /etc -mtime +5 //修改时间超过5天
find /etc -mtime -5 //修改时间等于5天
find /etc -mtime -5 //修改时间5天以内
5)按文件属主丶属组查找
find /home -user jack //属主是jack的文件
find /home -group hr //用户组是hr的文件
find /home -user jack -group hr
find /home -user jack -a -group hr
find /home -user jack -o -group hr
find /home -nouser //文件没有属主
find /home -nogroup //文件没有用户组
find /home -nouser -o nogroup
6)文件类型
find /dev -type f //普通文件
find /dev -type d //目录文件
find /dev -type l //链接
find /dev -type b //块设备
find /dev -type c //字符设备
find /dev -type s //套接字文件
find /dev -type p //管道文件
7)按文件权限
find . -perm 644 -ls //权限精确匹配
find . -perm -600 -ls //属主只要有读权限就行
find . -perm -222 -ls //ugo只要有w权限
find /usr/bin /usr/sbin -perm -4000 -ls //suid权限
find /usr/bin /usr/sbin -perm -2000 -ls //sgid权限
find /usr/bin /usr/sbin -perm -1000 -ls //sticky权限
-表示模糊匹配
8)找到后的动作:默认动作是-print
-print
-ls
-delete
-exec //后面跟自定义的shell命令
-ok //后面跟自定义的shell命令
find /etc -name "ifcfg*" -print //打印文件名
find /etc -name "ifcfg*" -ls //相当于ls -l
find /etc -name "ifcfg*" -exec cp -rf {} /tmp \;
find /etc -name "ifcfg*" -ok cp -rf {} /tmp \;
find /etc -name "ifcfg*" -exec rm -rf {} \;
find /etc -name "ifcfg*" -delte
find /etc -name "ifcfg*" | xargs rm -rf
9)find与xargs结合
find /etc -name "ifcfg*" | xargs -I {} cp -rf {} /var/tmp //复制文件
find /etc -name "ifcfg*" | xargs rm -rf //删除文件
10)find高级用法
mkdir dir1
touch dir1/file{1..10}
find dir1/ ! -name "file1" //取反
find dir1/ -name "file1" -o -name "file5" -ls //只能显示1个文件
find dir1/ \( -name "file1" -o -name "file5" \) -ls //同时显示两个文件
find dir1/ \( -name "file1" -o -name "file5" \) | xargs rm -rf
查找文件which locate find的更多相关文章
- Linux 利用 locate 和 find 查找文件
Linux 利用 locate 和 find 查找文件 命令 locate 用于快速查找文件.文件夹.此命令并没有在磁盘上查找所有文件,而是在预先建立的数据库里进行搜索.可以使用 updatedb 命 ...
- locate 最快的查找文件的命令 NB
我见过最NB的查找文件最快的命令 [root@NB data]# locate teamviewer. /data/Software/teamviewer.i686.rpm /home/ok/.loc ...
- Linux下查找文件:which、whereis、locate、find 命令的区别
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索.which 查看可执行文件的位置,通过环境变量查whereis 查看文件的位置,通过数据库查,每 ...
- Linux下相关查找文件命令(find locate which whereis type)
以下内容摘自:http://blog.csdn.net/jessica1201/article/details/8139249 标注的内容为自己的补充: 我们经常需要在系统中查找一个文件,那么在lin ...
- Linux下which、whereis、locate、find 命令查找文件
转自:http://blog.csdn.net/gh320/article/details/17411743 我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索 ...
- linux文件查找-find和locate
一.find 使用语法:find [查找目录] [查找规则] [查找完后执行的action] find是根据具体目录进行搜索 1.查找目录 如果不指定查找目录,默认在当前目录下进行查找 如果需要 ...
- Linux 查找文件命令 find whereis locate
Linux 有三个查找文件的命令:find, whereis, locate 其中find 不常用,whereis与locate经常使用,因为find命令速度较慢,因为whereis与locate是利 ...
- Linux上的文件查找工具之locate与find
前言 Linux上提供了两款工具用于查找文件,一款是locate,另一款是find. locate的特点是根据已生成的数据库查找,速度较快,但是查找的是快照数据,不准确. 因此在日常使用中,为了准确性 ...
- linux文件名称查找which,whereis,locate
1. 文件名称查找 使用find查询时.因为磁盘查询.所以速度较慢. 所以linux下查询更常使用which, whereis, locate来查询,因为是利用数据库查询.所以速度非常快. 2. wh ...
随机推荐
- Japan POJ - 3067 转化思维 转化为求逆序对
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
- C#学习之泛型继承和静态成员
想要理解这里有必要先将泛型类学习充分.这里讲解的是泛型类继承类的类型和静态成员. 在前面C#学习之泛型中,创建的LinkList<T>类实现了IEnumerable<T>接口. ...
- NYOJ 740 DP
“炫舞家“ST 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 ST是一个酷爱炫舞的玩家.TA很喜欢玩QQ炫舞,因此TA也爱屋及乌的喜欢玩跳舞机(Dance Danc ...
- 二叉树系列 - 二叉树里的最长路径 例 [LeetCode] Binary Tree Maximum Path Sum
题目: Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start ...
- [LeetCode] 16. 3Sum Closest ☆☆☆
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- JAVA--结果集已耗尽
有两个可能 1.rs ,state和conn没有关闭 rs.close(); state.close(); conn.close(); if(rs!=null) rs.close; if(sta ...
- 可能是国内最火的开源项目 —— C/C++ 篇
程序员们,在北上广你还能买房吗? >>> 推荐阅读: 可能是最火的开源项目 -- Java 篇 可能是国内最火的开源项目 -- PHP 篇 可能是国内最火的开源项目 -- Pyt ...
- 51Nod 1133 不重叠的线段 | 典型贪心
Input示例 3 1 5 2 3 3 6 Output示例 2 题意:给出n条一维线段,求不重合的最多线段数. 解析:这个是典型的贪心算法的区间问题. 贪心策略:每次取尽可能短的区间,而且保证相互之 ...
- JAVA嵌套类:静态嵌套类和非静态嵌套类
1.内部类定义 内部类在维基百科的定义为: 面向对象编程中,内部类(又叫做嵌套类)是在另一个类或者接口中进行声明的类.内部类不同于子类(subclass).(译者注:wiki的注解有误,内部类和嵌套 ...
- PowerDesigner16 修改表或表的字段Name的时候不让Code不自动跟着变
在修改表或表的字段Name的时候不让Code不自动跟着变,设置如下: tools-> General Options-> Dialog 去掉勾选 Name To Code mirror ...