2012-01-06 43 views
1

在下面的代碼中,我期望看到由find命令打印的find_examples_out/.t1,find_examples_out/.t2和find_examples_out/.s1文件,但由於某種原因它們被排除。他們顯示在子目錄中很好。當試圖用find命令修剪隱藏的dirs時,它似乎「修剪」頂部dir中隱藏的文件?

測試腳本:

#!/bin/csh 
# GNU find version 4.1.20 

find -version 
mkdir find_examples_out 
cd find_examples_out 
set FILES = (t1 .t1 t2 .t2 s1 .s1) 
set DIRS = (.hidden normal notnormal another) 

foreach f ($FILES) 
    touch $f 
end 

foreach i ($DIRS) 
    mkdir $i 
    cd $i 
    foreach f ($FILES) 
     touch $f 
    end 
    cd .. 
end 
echo "Files present:" 
ls -AR 

echo 
echo "Give me all files but exclude some paths:" 
find .      \ 
    \(      \ 
     -path "\.?.*"  \ 
     -o -path "*normal*" \ 
    \)      \ 
    -prune     \ 
    -o      \ 
          \ 
    \(      \ 
     -type f    \ 
    \)      \ 
    -print 

cd .. 
rm -rf find_examples_out 

這裏是輸出:

GNU find version 4.1.20 
Files present: 
.: 
another .hidden normal notnormal s1 .s1 t1 .t1 t2 .t2 

./another: 
s1 .s1 t1 .t1 t2 .t2 

./.hidden: 
s1 .s1 t1 .t1 t2 .t2 

./normal: 
s1 .s1 t1 .t1 t2 .t2 

./notnormal: 
s1 .s1 t1 .t1 t2 .t2 

Give me all files but exclude some paths: 
./t1 
./t2 
./s1 
./another/t1 
./another/.t1 
./another/t2 
./another/.t2 
./another/s1 
./another/.s1 

缺少什麼我在這裏?

+1

csh腳本也許應該有'#/斌/ CSH在頂部-f'! '-f'告訴它不要讀你的啓動文件('.cshrc'和'.login'),這樣(a)使它啓動得更快,並且(b)避免依賴於你自己的個人環境。 – 2012-01-12 04:14:58

+0

感謝您的提示。 – stephenmm 2012-01-18 16:48:31

回答

1

除非我忽略了某些內容,否則-path開關用於比較路徑的模式,包括文件名。 「?\ *。」

人體工程學,你-path開關將匹配的隱藏文件」 .t1" 等

FWIW:在發現我(v4.4.2)的版本, -path的參數是一個shell模式,而不是正則表達式。但是,我使用bash並且從未使用過csh,所以也許這會有所作爲。

編輯:我試圖添加此作爲評論,但它不斷破壞格式。

您可以使用它來實現什麼(我覺得)你正在努力實現:

find . \(\(-path "\.?.*" -type d \) -o -path "*normal*" \) -prune -o \(-type f \) -print 
+0

多數民衆贊成它,謝謝你爲我清理它。似乎選項「-path」不是一個很好的名字,因爲它會過濾文件名以及路徑...... – stephenmm 2012-01-11 20:56:21