2023年7月26日发(作者:)
编程-⽂件查找之find命令3.1.语法格式find [路劲][选项][操作]选项参数对照表3.2.-name
查找/etc/⽬录下以.conf结尾的⽂件find /etc/ -name "*.conf"-iname 不区分⼤⼩写find /etc/ -iname "*.conf"-user 查找当前⽬录为root⽤户的⽂件find ./ -user root3.3.-type
⽂件的类型f ⽂件d ⽬录c 字符设备⽂件b 块设备⽂件l 链接⽂件p 管道⽂件 find . -type ffind . -type d3.4.-size⽂件⼤⼩-n ⼩与n的⽂件+n ⼤于n的⽂件 查找/etc⽬录下⼩与100k的⽂件find /etc -size -100k查找/etc⽬录下⼤于1M的⽂件find /etc -size +1M3.5.-mtime修改时间-n n天以内修改的⽂件+n n天以外修改的⽂件n 正好n天修改的⽂件 查找/etc⽬录下5天之内修改并且以conf结尾的⽂件find /etc -mtime -5 -name '*.conf'查找/etc⽬录下10天之前修改并且属主为root的⽂件find /etc -mtime +10 -user root3.6.-mmin-n n分钟以内修改的⽂件+n n分钟以外修改的⽂件修改/etc⽬录下30分钟以内修改的⽬录find /etc -mmin -30 -type d3.7.-mindepth
表⽰从n级⼦⽬录开始搜索find /etc -mindepth 3 -type -f-madepth n表⽰最多搜索到n-1级⼦⽬录3.8.操作-exec对搜索的⽂件常⽤操作 -print 打印输出-exec 对⽂件执⾏特定的操作-ok 和exec功能意义,只是每次操作都会给⽤户提⽰-exec的格式为-exec 'command' {} 例⼦⼀:搜索/home/shell_learn/下的⽂件,⽂件名以.sh结尾,且修改时间在⼀个星期之内的,然后将其删除#打印find /home/shell_learn/ -type f -name '*.sh' -mtime -7 -print#复制find /home/shell_learn/ -type f -name '*.sh' -mtime -7 -exec cp {} /home/shell_learn/test/ ;#删除find /home/shell_learn/ -type f -name '*.sh' -mtime -7 -exec rm -rf {} ;命令locate不同于find命令是在整块磁盘中搜索,locate命令是在数据库⽂件中查找find是默认全局匹配,locate则是默认部分匹配updatedb命令⽤户更新/var/lib/mlocate/所使⽤的配置⽂件/etc/ 实例:updatedb命令把⽂件更新到数据库(默认是第⼆天系统才会⾃动更新到数据库),否则locate查找不到[root@VM_0_9_centos shell_learn]# touch [root@VM_0_9_centos shell_learn]#
[root@VM_0_9_centos shell_learn]# locate [root@VM_0_9_centos shell_learn]#
[root@VM_0_9_centos shell_learn]# updatedb[root@VM_0_9_centos shell_learn]#
[root@VM_0_9_centos shell_learn]# locate /home/shell_learn/[root@VM_0_9_centos shell_learn]#3.10 .whereis命令实例[root@VM_0_9_centos shell_learn]# whereis mysqlmysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/[root@VM_0_9_centos shell_learn]#
[root@VM_0_9_centos shell_learn]# whereis -b mysqlmysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql[root@VM_0_9_centos shell_learn]#
[root@VM_0_9_centos shell_learn]# whereis -m mysqlmysql: /usr/share/man/man1/[root@VM_0_9_centos shell_learn]#
作⽤:仅查找⼆进制程序⽂件[root@VM_0_9_centos shell_learn]# which mysql/usr/bin/mysql[root@VM_0_9_centos shell_learn]#
3.12.各查找命令总结
发布者:admin,转转请注明出处:http://www.yc00.com/web/1690363808a338320.html
评论列表(0条)