Centos之文件搜索命令find

摘要:
[ root@localhost~]#Ls222anaconda-ks.cfg公牛力量公牛[root@localhost~]#查找/-name妞妞/root/Nouniu/tmp/Nouniu[root@localhost~]#查找/-name cow[root@localhost~]#我们发现搜索牛可以找到结果,但搜索牛,没有结果,所以查找搜索是完全匹配的搜索;如果我们需要进行模糊查询,我们需要使用通配符*匹配任何内容?匹配任何字符[]以匹配括号中的任何字符。让我们创建一些文件来测试[root@localhost~]#Ls222anaconda-ks.cfg牛比牛比2牛比牛2[root@localhost ~]#[ root@localhost~]#查找/-name“Niu*”/root/Nubi/root/Nouniu/root/Noubi 2/root/Nou妞2/tmp/Nouniu查找所有以“Niu”开头的文件[root@localhost~]#查找/根名称“奶牛?

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 ~]# 

转自kika

免责声明:文章转载自《Centos之文件搜索命令find》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇使用 Visual Studio Code 创建并运行 Transact SQL 脚本Nginx打开目录列表功能下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Centos6.5 恢复误删的系统面板

  在CentOS6.5下往面板上拖应用程序时,手贱了,点了"Delete This Panel".结果就悲剧了~面板不见了!   从网上搜了一下解决方法,列举一下。   1.新建面板   如果下面的面板还在的话,右键选择"New Panel",就可以看到一个空白的面板了,   然后右键面板选择"Add To Panel",选择要添加的程序就可以了。   ...

awk命令

简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大。简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理。 awk有3个不同版本: awk、nawk和gawk,未作特别说明,一般指gawk,gawk 是 AWK 的 GNU 版本。 awk其名称得...

centos 6.5源码编译安装subversion 1.8.10

一、简介 CentOS 6.5的yum源可以安装的SVN客户端版本太低了,1.6.11,所以需要升级到1.8.10,而官网有没有找到1.8.10的安装包,只能选择源码编译安装。 二、安装步骤 参考官网:http://svn.apache.org/repos/asf/subversion/trunk/INSTALL 源码下载:http://archive.a...

shell编程之sed

一、sed (Stream Editor) 1、定位行: sed -n '12,~3p' pass #从第12行开始,直到下一个3的倍数行(12-15行) sed -n '12,+4p' pass #从第12行开始,连续4行(12-16行) sed -n '12~3p' pass #从第12行开始,间隔3行输出一次(12,15,18,21...) se...

如何让 ssh 允许以 root 身份登录

默认情况下,Pack 上的 root 用户不能用通过密码来远程登录,可以用一下命令来做:(注意要在 root 权限下) sed -i 's/PermitRootLoginswithout-password/PermitRootLogin yes/g' /etc/ssh/sshd_config 以上这条命令就是手动修改/etc/ssh/sshd_conf...

kubernetes 里面pod时间修改

yaml文件中设置时区同步,只需要映射主机的“/etc/localtime”文件。 apiVersion: extensions/v1beta1kind: Deploymentmetadata:name: mywebspec:replicas: 2template:metadata:labels:app: mywebspec:containers:- na...