find tar排除指定文件或目錄操作及查找文件內容關鍵字


 1.find查找排除單個目錄

查找當前目錄或者子目錄下所有.txt文件,但是跳過子目錄sk

find . -path "./sk" -prune -o -name "*.txt" -print

find . -type f -executable ! -path "./.git/*"

  • .:在當前目錄下查找

  • -type f:僅查找一般文件

  • -executable:文件具有可執行權限

  • ! -path "./.git/*":這里是關鍵,! 的作用是排除其后 -path 所跟的目錄

2.find查找排除多個目錄

find / path/home/opath/root -prune -nouser -type f -exec ls -l {} \;

find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print

3.tar根據文件列表壓縮指定文件

tar -czv -T /opt/src/downLoad_list.txt -f downLoad_list.txt.tar.gz
 
  -T, --files-from=FILE      get names to extract or create from FILE
      --unquote              unquote filenames read with -T (default)
  -X, --exclude-from=FILE    exclude patterns listed in FILE
 
-T 指定需要壓縮的文件列表,只壓縮文件列表里的文件
-f 指定壓縮文件名及路徑
-X 排除指定文件,不進行壓縮

4.find查找指定文件內容包含特定關鍵字

find . -type f -name '*.jsp' -exec awk 'BEGIN{ FS="\n"; RS="" } /關鍵字1/&&/ 關鍵字2/ {print FILENAME}' {} \;

awk查詢的是這倆關鍵字同時出現在find查詢的文件中的,是與的關系

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM