パターンと一致しない現在のディレクトリでファイルを検索する

パターンと一致しない現在のディレクトリでファイルを検索する

入れ子になったディレクトリを除外するように2番目のディレクティブのパターンを変更するにはどうすればよいですか? (これは内容ではなくls返します)。foo.mp4bar:

$ ls *
foo.mp4 foo.ogg

bar:
bar.ogg
$ shopt -s extglob
$ ls !(*.ogg)
foo.mp4

bar:
bar.ogg

PS:私はOS Xを使用しています。

ベストアンサー1

.Usefindの代わりに使用すると、1つ以上のglob式を除外できます。あなたの例(およびOSX)では、次のことができます。lsfind

find * -depth 0 -type f ! -name '*.ogg'  -ls

次の結果が生成されますls -l(与えられたファイルのみ-type f)。

66294163        0 -rw-r--r--    1 tom              wheel                   0 Sep  9 20:12 foo.mp4

OSX の場合、最初の列は inode 値で、次はリンク数です。 find次のような多くのリストオプションは提供されませんls

$ ls -l
total 0
drwx------  3 thomas  wheel  102 Sep  9 15:33 com.apple.launchd.OFStJ79qtq
drwx------  3 thomas  wheel  102 Sep  9 15:33 com.apple.launchd.VQsV1ae6bI
drwx------  3 thomas  wheel  102 Sep  9 15:33 com.apple.launchd.e6HBMt2vnS
drwx------  3 thomas  wheel  102 Sep  9 15:33 com.apple.launchd.he9U4OAIMI
-rw-r--r--  1 tom     wheel    0 Sep  9 20:12 foo.mp4
-rw-r--r--  1 tom     wheel    0 Sep  9 20:12 foo.ogg

しかし、効果があるかもしれません。

おすすめ記事