2012-01-06 9 views
1

以下のコードでfind_examples_out/.t1、find_examples_out/.t2、find_examples_out/.s1ファイルがfindコマンドによって出力されることが予想されますが、何らかの理由で除外されます。それらはサブディレクトリに表示されます。findコマンドで隠されたディレクトリを削除しようとすると、トップディレクトリの隠しファイルを "剪定"するように見えますか?

テストスクリプト:ここ

#!/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スクリプトは、おそらく上部に '#/ binに/ cshの-f'を持っている必要があります。 '-f'は、起動ファイル(' .cshrc'と '.login')を読み込まないように指示します。これは、(a)起動を速くし、(b)自分の個人環境への依存を避けます。 –

+0

チップをありがとう。 – stephenmm

答えて

1

私が何か見落としていない限り、-pathスイッチはファイルを含むパスに与えられたパターンを比較します。

エルゴ、あなたの-path "?。\ *"スイッチが隠しファイル」.t1" と一致しますなど

FWIW:私は(v4.4.2)を持っていることを見つけるのバージョンでは、 -pathへの引数はシェルパターンであり、正規表現ではありません。しかし、私はbashを使っていますが、cshを使ったことはありません。

編集:これをコメントとして追加しようとしましたが、フォーマットが破損しています。

あなたが達成しようとしている(と思う)ものを達成するためにこれを使用することができます!

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

それは私のためにそれをクリアしてくれてありがとう。オプション "-path"は、ファイル名だけでなくパスもフィルタリングするので、とても良い名前ではないようです... – stephenmm

関連する問題