Centos之文件搜索命令find
find [搜索范围] [搜索条件]
#搜索文件
find / -name install.log
#避免大范围搜索,会非常耗费系统资源
#find是在系统当中搜索符合条件的文件名。如果需要匹配,
使用通配符匹配,通配符是完全匹配。
[root@localhost ~]# ls
222 anaconda-ks.cfg 牛逼 牛牛
[root@localhost ~]# find / -name 牛牛
/root/牛牛
/tmp/牛牛
[root@localhost ~]# find / -name 牛
[root@localhost ~]#
我们发现 搜索牛牛 能搜索到结果,但是搜索牛,么有结果,
所以说 find搜索 是完全匹配搜索;
如果我们需要进行模糊查询,我们要使用通配符;
* 匹配任意内容
?匹配任意一个字符
[]匹配任意一个中括号的字符
我们创建一些文件来测试
[root@localhost ~]# ls
222 anaconda-ks.cfg 牛逼 牛逼2 牛牛 牛牛2
[root@localhost ~]#
[root@localhost ~]# find / -name "牛*"
/root/牛逼
/root/牛牛
/root/牛逼2
/root/牛牛2
/tmp/牛牛
查找开头是 “牛”的所有文件
[root@localhost ~]# find /root -name "牛?"
/root/牛逼
/root/牛牛
查找root目录下,所以“牛”开头然后后面接一位字符的文件
[root@localhost ~]# find /root -name "牛[牛逼]2"
/root/牛逼2
/root/牛牛2
[root@localhost ~]#
查找首尾分别是“牛”“2”,中间字符串是“牛逼”当中的任一字符的文件
find /root -iname anaconda-ks.cfg
不区分大小写
find /root -user root
根据所有者搜索
find /root -nouser
查找没有所有者的文件
[root@localhost ~]# find /root -iname Anaconda-ks.cfg
/root/anaconda-ks.cfg
[root@localhost ~]# find /root -name Anaconda-ks.cfg
[root@localhost ~]#
linux是严格区分大小写的,假如用iname 查询时不区分大小写;
[root@localhost ~]# find /root -user root
/root
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/anaconda-ks.cfg
/root/.bash_history
/root/牛逼
/root/牛逼/java.pdf
/root/222
/root/牛牛
/root/牛逼2
/root/牛牛2
root用户的所有文件
find /var/log/ -mtime +10
查找10天前修改的文件
-10 10天内修改的文件
10 10天当前修改的文件
+10 10天前修改的文件
atime 文件访问时间
ctime 改变文件属性
mtime 修改文件内容
[root@localhost ~]# find /var/log -mtime +10
/var/log/ppp
查找10天前的日志
find /root -size 2k
查找文件大小是1到2KB的文件(进一法)
-2k 小于2KB的文件
2k 等于2KB的文件
+2k 大于2KB的文件
find /root -inum 262422
查找i节点是262422的文件
[root@localhost ~]# find /root -size 2k
/root/anaconda-ks.cfg
/root/.bash_history
[root@localhost ~]# find /root -size -2k
/root
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/牛逼
/root/牛逼/java.pdf
/root/222
/root/牛牛
/root/牛逼2
/root/牛牛2
[root@localhost ~]# find /root -size +2k
[root@localhost ~]#
[root@localhost ~]# ls -i
33575031 222 801541 牛逼 33575023 牛牛
33574979 anaconda-ks.cfg 33605192 牛逼2 33605193 牛牛2
[root@localhost ~]# find /root -inum 33575023
/root/牛牛
[root@localhost ~]#
根据i节点来搜索
find /etc -size +20k -a -size -50k
查找/etc/目录下,大于20KB并且小于50KB的文件
-a and 逻辑与 ,两个条件都满足
-o or 逻辑或,两个条件满足一个即可
find /etc -size +20k -a -size -50k -exec ls -lh{} \ ;
查找/etc/目录下,大于20KB并且小于50KB的文件,并显示详细信息;
-exec/-ok 命令{} \; 对搜索结果执行操作;
[root@localhost ~]# find /etc -size +20k -a -size -50k
/etc/selinux/targeted/active/modules/100/apache/hll
/etc/selinux/targeted/active/modules/100/init/hll
/etc/selinux/targeted/active/modules/100/staff/cil
/etc/selinux/targeted/active/modules/100/staff/hll
/etc/selinux/targeted/active/modules/100/sysadm/cil
/etc/selinux/targeted/active/modules/100/sysadm/hll
/etc/selinux/targeted/active/modules/100/unprivuser/hll
/etc/selinux/targeted/active/modules/100/virt/hll
/etc/selinux/targeted/active/modules/100/xguest/hll
/etc/selinux/targeted/active/modules/100/xserver/hll
/etc/selinux/targeted/contexts/files/file_contexts.homedirs.bin
/etc/sysconfig/network-scripts/network-functions-ipv6
/etc/ld.so.cache
/etc/dnsmasq.conf
/etc/postfix/access
/etc/postfix/header_checks
/etc/postfix/main.cf
[root@localhost ~]# find /etc -size +20k -a -size -50k -exec ls -lh {}\;
find: 遗漏“-exec”的参数
[root@localhost ~]# find /etc -size +20k -a -size -50k -exec ls -lh {} \;
-rw-r--r--. 1 root root 25K 11月 12 2016 /etc/selinux/targeted/active/modules/100/apache/hll
-rw-r--r--. 1 root root 31K 11月 12 2016 /etc/selinux/targeted/active/modules/100/init/hll
-rw-r--r--. 1 root root 21K 11月 12 2016 /etc/selinux/targeted/active/modules/100/staff/cil
-rw-r--r--. 1 root root 36K 11月 12 2016 /etc/selinux/targeted/active/modules/100/staff/hll
-rw-r--r--. 1 root root 30K 11月 12 2016 /etc/selinux/targeted/active/modules/100/sysadm/cil
-rw-r--r--. 1 root root 46K 11月 12 2016 /etc/selinux/targeted/active/modules/100/sysadm/hll
-rw-r--r--. 1 root root 31K 11月 12 2016 /etc/selinux/targeted/active/modules/100/unprivuser/hll
-rw-r--r--. 1 root root 29K 11月 12 2016 /etc/selinux/targeted/active/modules/100/virt/hll
-rw-r--r--. 1 root root 21K 11月 12 2016 /etc/selinux/targeted/active/modules/100/xguest/hll
-rw-r--r--. 1 root root 30K 11月 12 2016 /etc/selinux/targeted/active/modules/100/xserver/hll
-rw-r--r--. 1 root root 44K 11月 12 2016 /etc/selinux/targeted/contexts/files/file_contexts.homedirs.bin
-rw-r--r--. 1 root root 27K 9月 12 2016 /etc/sysconfig/network-scripts/network-functions-ipv6
-rw-r--r--. 1 root root 27K 6月 10 05:21 /etc/ld.so.cache
-rw-r--r--. 1 root root 25K 11月 12 2016 /etc/dnsmasq.conf
-rw-r--r--. 1 root root 21K 6月 10 2014 /etc/postfix/access
-rw-r--r--. 1 root root 22K 6月 10 2014 /etc/postfix/header_checks
-rw-r--r--. 1 root root 27K 6月 10 2014 /etc/postfix/main.cf
[root@localhost ~]#
Centos之文件搜索命令find的更多相关文章
- (八)Centos之文件搜索命令locate
一.文件搜索命令locate locate优点是 搜索速度快 ,缺点是只能按文件名搜索: 1.1 新建一个文件 1.2 更新数据库 locate命令搜索的是 /var/lib/mlocate 下的 ...
- Centos之文件搜索命令locate
locate命令 locate 文件名 在后台数据库中按文件名搜索,搜索速度更快 /var/lib/mlocate #locate命令所搜索的后台数据库 updatedb 更新数据库 locate搜索 ...
- Centos locate 文件搜索命令(十一)
locate命令 locate 文件名 在后台数据库中按文件名搜索,搜索速度更快 /var/lib/mlocate #locate命令所搜索的后台数据库 updatedb 更新数据库 locate搜索 ...
- (十)Centos之文件搜索命令find
1.1 find [搜索范围] [搜索条件](搜索文件) find是在系统当中搜索符合条件的文件名. 如果需要匹配,使用通配符匹配,通配符是完全匹配. * 匹配任意内容 ?匹配任意一个字符 []匹配任 ...
- 4.Linux的文件搜索命令
1.文件搜索命令 which 语法:which [命令名称] 范例:$which ls 列出ls命令所在目录 [chanshuyi@localhost ~]$ which ls alias ls= ...
- 第3章 Linux常用命令(3)_文件搜索命令
3. 文件搜索命令 3.1 文件搜索:find (1)find命令 命令名称 find 命令所在路径 /bin/find 执行权限 所有用户 语法 find [搜索范围] [-选项] [匹配条件] - ...
- Linux常用命令学习2---(文件搜索命令locate find、命令搜索命令whereis which、字符串搜索命令grep、帮助命令man)
1.文件搜索命令:locate [文件名] 在后台数据库中按文件名搜索,搜索速度比find快,耗费资源更少 例子:locate test.txt,就会显示文件名包含 test.txt的所 ...
- Linux文件搜索命令
文件搜索命令:locate locate 文件名 在后台数据库中按文件名搜索,搜索速度很快(比find命令要快得多) locate命令所搜索的后台数据库的位置:/var/bin/mlocate 支持模 ...
- linux笔记:linux常用命令-文件搜索命令
文件搜索命令:find(文件搜索) 一些示例: 注意:在以文件名为条件进行搜索时,支持通配符. 多条件搜索,以及直接对搜索到的文件进行操作: 文件搜索命令:locate(在文件资料库中查找文件) 文件 ...
随机推荐
- Jmeter中正则表达式不区分大小写进行匹配
(?i)<r i="([A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12})" ...
- C变参数函数demo
#include <stdio.h> #include <stdarg.h> int sum(int a,...) { int temp = 0,sum=0,count ...
- mysql 导入导出摘要
1.导入by数据文件. mysql>load data infile '文件路径' into table 表名 fields terminated by '字段分隔符' lines termin ...
- event对象的理解
0.给对象绑定事件准确的说是给对象事件绑定事件函数 1.event:事件对象,当一个事件发生的时候,和当前这个对象发生的事件有关的信息都会被i临时保存到event对象中 2.event对象必须在一个事 ...
- centos6.8下redis的安装和配置
centos6.8下redis的安装和配置 下载.安装 在redis官网可以获取到最新版本的redis 进入/usr/local/目录,执行如下命令 wget http://download.redi ...
- Activiti中23张表的含义
1.与流程定义相关的4张表: 2.与执行任务相关的5张表: 3.与流程变量相关的2张表
- 2018.10.14 loj#6003. 「网络流 24 题」魔术球(最大流)
传送门 网络流好题. 这道题可以动态建图. 不难想到把每个球iii都拆点成i1i_1i1和i2i_2i2,每次连边(s,i1),(i2,t)(s,i_1),(i_2,t)(s,i1),(i2, ...
- golang闭包里的坑
介绍 go的闭包是一个很有用的东西.但是如果你不了解闭包是如何工作的,那么他也会给你带来一堆的bug.这里我会拿出Go In Action这本书的一部分代码,来说一说在使用闭包的时候可能遇到的坑.全部 ...
- codevs 1083
这道题是看了人家大牛的解题报告: 对了,要说明一下,(A+B)&1 ,表示,判断(A+B)是奇数否? 下面给出代码: #include<iostream> #include< ...
- hdu2844
题目 这道题,刚开始题没读懂,就是这句话:,A1,A2,A3...An and C1,C2,C3...Cn corresponding to the number of Tony's coins of ...