在下面的代碼中,我期望看到由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
缺少什麼我在這裏?
csh腳本也許應該有'#/斌/ CSH在頂部-f'! '-f'告訴它不要讀你的啓動文件('.cshrc'和'.login'),這樣(a)使它啓動得更快,並且(b)避免依賴於你自己的個人環境。 – 2012-01-12 04:14:58
感謝您的提示。 – stephenmm 2012-01-18 16:48:31