雲計算學習days4-----find命令

find 命令

用於文件查找shell

·find /path -

參數

-type 基於類型 
 
 f d s c b l 文件類型 
 find /etc -type f -name "ifc*"
 
 [root@localhost mnt]# find /etc -type f -name "ifc*"
 
 /etc/sysconfig/network-scripts/ifcfg-lo
 /etc/sysconfig/network-scripts/ifcfg-ens33
 
 
 
 -size 基於大小
  
 +5M 大於5M的文件
 5M 等於5M的文件
 -5M 小於5M的文件
 
 find /etc -type f -size +100K | xargs ls -hl 顯示大於100k的文件
 
 
 -mtime 基於時間
 
 +7 7天之前
 7 第7天
 -7 最近7天
 
 
 find /etc -type f -name "file-*" -mtime +7 |xargs rm -f 
 保留最近7天的文件,刪除7天之前的文件
 
 -user  基於用戶
 -group 基於組
  
  find /home -user jack
  在目錄下找到屬主jack的文件
  
  find /home -group jack
  在目錄下找到屬組的文件
  
  -nouser -nogroup
  查找沒有屬主或則屬組的文件
  
  -a 而且  -o 或者
  
  # -nouser -a -nogroup 
  
  
  -delete 刪除
  -ok 後面跟自定義shell命令(會提示是否操做)
  
  -exec 逐個執行但不會提示
  find -type f -name "file*" -exec cp -rv {} /tmp \;
  同
  find -type f -name "file*" | xargs cp -rvf /tmp/
  
  -exec後面跟着shell命令
  cp -rv {} /tmp 
  {}就是find找到的東西,就是參數
  /tmp 複製到的地方 
  
 \;是固定搭配
  
 ! 取反

### 過濾code

·find ./ -type f |xargs grep "XX"
 從文件中找到寫有XX的文件
相關文章
相關標籤/搜索