做网站 编程语言,中国建设银行个人信息网站,怎样加强组织建设,网站优秀作品文章目录
find
命令介绍
语法格式
命令基本参数
参考实例
1#xff09;在root/data目录下搜索*.txt的文件名
2#xff09;搜索一天以内最后修改时间的文件#xff1b;并将文件删除
3#xff09;搜索777权限的文件
4#xff09;搜索一天之前变动的文件复制到test…文章目录
find
命令介绍
语法格式
命令基本参数
参考实例
1在root/data目录下搜索*.txt的文件名
2搜索一天以内最后修改时间的文件并将文件删除
3搜索777权限的文件
4搜索一天之前变动的文件复制到test目录下
5搜索指定用户的文件
6在/etc目录下搜索大于5M小于10M的文件
7搜索指定组的目录
8在/var/log目录搜索指定后缀的文件 9在/var/log目录搜索指定后缀不是.log的文件
10从根目录下搜索可执行的文件并复制到目录下
命令总结
find
命令介绍 通过帮助文档了解含义 NAME find - search for files in a directory hierarchy find命令的作用是在目录层次结构中搜索文件所在的位置此命令可以使用的参数很多同时支持正则表达式结合管道符后能够实现更加复杂的功能是必须掌握的命令之一。 通常find是从根目录开始全盘搜索不同于其他几个搜索文件的命令find搜索时会消耗较多的系统资源在服务器负载较高的时候不建议从根目录开始搜索。
语法格式 find参数是比较多的而且很多参数都是长格式要记住真的要花一番心思下面来看下语法格式find 【路径】【参数】 SYNOPSIS find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression] 命令基本参数
此命令的常用参数有以下这些以表格形式显示
-name匹配文件的名称-user匹配用户的文件所有者-group匹配组的文件所有组-mtime -n n匹配修改内容的时间-n表示n天之内n表示n天之前-atime -n n匹配访问文件的时间-n表示n天之内n表示n天之前-ctime -n n匹配改动文件的时间-n表示n天之内n表示n天之前-perm匹配文件权限-size匹配文件的大小单位k Mnk表示查找大于n的文件-nk表示查找小于n的文件-exec { } \;后面可跟用于进一步处理搜索结果的命令-prune忽略某个目录-nouser匹配不是这个用户的文件-nogroup匹配不是这个组的文件 -type 匹配文件类型b d c p f l-type参数的文件类型 b块设备文件d目录文件c字符设备文件p管道文件f 文本文件l 链接文件参考实例
1在root/data目录下搜索*.txt的文件名
[rootlocalhost ~]# find /root/data -name *.txt
/root/data/1.txt
/root/data/2.txt
/root/data/3.txt
/root/data/4.txt
/root/data/5.txt2搜索一天以内最后修改时间的文件并将文件删除
使用-exec参数将前面的文件进行处理也可使用find配合xargs将文件进行删除。
[rootlocalhost ~]# find /root/data -mtime -1
/root/data
/root/data/1.txt
/root/data/2.txt
/root/data/3.txt
/root/data/4.txt
/root/data/5.txt
[rootlocalhost ~]# find /root/data -mtime -1 -exec rm -f {} \; [rootlocalhost ~]# find /root/data -mtime -1 |xargs -i rm -f {}[rootlocalhost ~]# ll /root/data/
总用量 0
3搜索777权限的文件
[rootlocalhost ~]# find / -type f -perm 777
4搜索一天之前变动的文件复制到test目录下
[rootlocalhost ~]# find /etc -type f -ctime 1 -exec cp -a {} /root/test \;
[rootlocalhost ~]# ll /root/test | wc -l
1252
5搜索指定用户的文件
[rootlocalhost ~]# find / -type f -user host
6在/etc目录下搜索大于5M小于10M的文件
[rootlocalhost ~]# find /etc -type f -size 5M -and -size -10M
/etc/udev/hwdb.bin7搜索指定组的目录
[rootlocalhost ~]# find / -type d -group host
/var/tmp/yum-host-u08wM2
/var/tmp/yum-host-u08wM2/x86_64
/var/tmp/yum-host-u08wM2/x86_64/7
[rootlocalhost ~]# find / -type d -group host | wc -l
188在/var/log目录搜索指定后缀的文件
-iname表示不区分大小写的的文件名称
[rootlocalhost ~]# find /var/log -type f -iname *.log
/var/log/tuned/tuned.log
/var/log/audit/audit.log
/var/log/anaconda/anaconda.log
/var/log/anaconda/X.log
/var/log/anaconda/program.log
/var/log/anaconda/packaging.log
/var/log/anaconda/storage.log
...... 9在/var/log目录搜索指定后缀不是.log的文件
[rootlocalhost ~]# find /var/log -type f ! -name .log | wc -l
7110从根目录下搜索可执行的文件并复制到目录下
[rootlocalhost /]# find / -type f -perm /ax -exec cp -a {} /root/sys_sh \;命令总结 find命令很多参数都可以结合起来一起使用的关键还是要能记住每个参数可以实现的功能。若觉得以上内容还行可以点赞支持一下!