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/−o−path/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}' {} \;