すべて「コース」で始まるサブディレクトリのディレクトリを調べる必要がありますが、バージョンは次のとおりです。例えば
course1.1.0.0
course1.2.0.0
course1.3.0.0
では、ディレクトリの正しいリストを表示するには、コマンドをどのように変更すればよいでしょうか?
find test -regex "[course*]" -type d
できるよ:
find test -type d -regex '.*/course[0-9.]*'
名前course
に数字とドットを加えたファイルに一致します。
例えば:
$ ls course*
course1.23.0 course1.33.534.1 course1.a course1.a.2
$ find test -type d -regex '.*course[0-9.]*'
test/course1.33.534.1
test/course1.23.0
ブラケットを削除し、正規表現に適切なワイルドカード構文を使用する必要があります ( .*
):
find test -regex "course.*" -type d
-name
の代わりにオプションを使用して、より使い慣れたシェル ワイルドカード構文を使用することもできます-regex
。
find test -name 'course*' -type d
バージョン番号のサブディレクトリを正確に一致させるには、正規表現を使用することをお勧めします。
find . -type d -iregex '^\./course\([0-9]\.\)*[0-9]$'
テスト:
ls -d course*
course1.1.0.0 course1.1.0.5 course1.2.0.0 course1.txt
find . -type d -iregex '^\./course\([0-9]\.\)*[0-9]$'
./course1.1.0.0
./course1.1.0.5
./course1.2.0.0
更新:正確に 3 回一致させるには、次の[0-9].
検索コマンドを使用します。
find test -type d -regex '.*/course[0-9]\.[0-9]\.[0-9]\.[0-9]$'