本文共 993 字,大约阅读时间需要 3 分钟。
查找文件
• 根据预设的条件递归查找对应的文件– find [目录] [条件1] [-a|-o] [条件2] ...-a多个条件同时满足 -o满足一个条件– 常用条件表示: -type 类型(f文件、d目录、l快捷方式) -name "文档名称" -size +|-文件大小(k、M、G) -user 用户名
-type 类型(f文件、d目录、l快捷方式)find /boot/ -type l 查找快捷方式 find /boot/ -type d 查找是目录find /boot/ -type f 查找是文件
-name "文档名称"find /boot/ -name "vm*" 以vm开头的查找出来
-size +|-文件大小(k、M、G)find /boot/ -size +10M 查找boot大于10M的查找出来
-user 用户名find / -user student 查找用户所有者创造的文档(目录和文件)
根据名称查找,忽略大小写 -inamefind /etc/ -iname "PASSWD" 忽略大小写查找
根据所属组进行查找 -groupfind /home/ -group student查找用户所属组创造的文档(目录和文件)
限制目录查找的深度(最大层数) -maxdepthfind /etc/ -maxdepth 1 -name "*.conf"在etc下以.conf结尾的父目录和子目录
根据文件修改时间(所有的时间,都是过去时间) -mtime -mtime +10 #10天之前的文档 -mtime -10 #最近10天之内的文档 find /var/log/ -mtime +1000find /var/log/ -mtime +90 cat -n /var/log/messages
使用find命令的 -exec 操作find .. .. -exec 处理命令 {} \;优势:以 {} 代替每一个结果,逐个处理,遇 \; 结束find /etc -name "*tab"find /etc -name "*tab" -exec cp {} /opt \;ls /opt
转载地址:http://krnwi.baihongyu.com/