Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

find -exec 參數深度解析:語法、花括號代換、分號轉義、實戰刪除舊檔

編輯:關於 Linux

find 的 -exec 可對搜尋結果逐一執行指令,語法關鍵:

  • -exec command {} \;:{} 代換檔名,\; 結束標記(需轉義分號)。
  • 每個匹配檔案啟動一個子程序,大量檔案效能較差。
  • 建議先用 -exec ls -l {} \; 預覽,確認無誤再改 rm。

實例 1:列出所有一般檔案詳細資訊

find . -type f -exec ls -l {} \;

實例 2:刪除 14 天前修改的一般檔案

find . -type f -mtime +14 -exec rm {} \;

注意:-exec 會將所有匹配檔案一次傳遞給指令,若參數過長可能溢出。大量檔案建議改用 xargs 分批處理(見下一篇)。

上一頁123下一頁共3頁

Copyright © Windows教程網 All Rights Reserved