一、find的作用?
?遞回式查找
?根據預設的條件遞回查找對應的檔案
二、find使用方法
– find [目錄] [條件1]…
-type 型別(f文本檔案、d目錄、l快捷方式)
代碼如下:
[root@localhost ~]# find /home -type f
[root@localhost ~]# find /root -type f
[root@localhost ~]# find /home -type d
[root@localhost ~]# find /root -type d
[root@localhost ~]# find /etc -type l
-name “名稱”
代碼如下:
[root@localhost ~]# find /etc/ -name "*.conf"
[root@localhost ~]# find /etc/ -name "*tab*"
[root@localhost ~]# find /etc/ -name "passwd"
-size +或-檔案大小(k、M、G)
[root@localhost ~]# find /boot/ -size +20M
[root@localhost ~]# find /boot/ -size -10M
[root@localhost ~]# find /boot/ -size +300k
-user 用戶名 #按照資料的所有者
[root@localhost ~]# useradd wxr #新建用戶
[root@localhost ~]# find /home -user zhangsan
-mtime 修改時間 #都是過去時間
三個月之前的資料:
[root@localhost ~]# find /root -mtime +90
查找最近一天內:
[root@localhost ~]# find /root -mtime -1
三、find高級使用處理查找的內容
案例:查找并處理檔案
1. 利用find查找所有用戶 student 擁有的必須是檔案,把它們拷貝到 /root/findfiles/ 檔案夾中
[root@localhost ~]# useradd student
[root@localhost ~]# mkdir /root/findfiles
[root@localhost ~]# find / -user student -type f
[root@localhost ~]# find / -user student -type f -exec cp {} /root/findfiles/ \;
[root@localhost ~]# ls -A /root/findfiles/
? 操作方法:
find [范圍] [條件] -exec 處理命令 {} ;
– -exec :額外操作開始
– {} :find查詢的結果
– ; :額外操作結束
– 每找到一個符合條件的資料,直接傳輸給-exec,每次只傳輸一個引數
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/65982.html
標籤:其他
上一篇:解決方法:Grafana6.x使用grafana-cli命令在線安裝zabbix插件,新增zabbix資料源出現報錯
