
毎日の開発タスクの一環として(OS 10.12.3 を実行している Mac で)、tail -f *
ターミナルからログ フォルダーを実行します。フォルダーには約 15 個の異なるファイルが含まれています。このコマンドを変更して、変更を監視するにはどうすればよいでしょうか。1つを除くすべてのファイルから*
? から除外したい唯一のファイル*
が というファイルだとしますRepetitive.log
。
非常に基本的な質問で申し訳ありません。探してみましたが、重複した質問は見つかりませんでした。https://stackoverflow.com/questions/42815599/exclude-files-from-the-catchall-symbol
答え1
シェルとして使用している場合はbash
、環境変数GLOBIGNORE
にコロンで区切られたパターンのリストを設定します。ないシェルがグロブしているときに一致します。例えば
$ export GLOBIGNORE=Repetitive.log
$ export GLOBIGNORE=somefile:anotherfile:abc*
からman bash
:
GLOBIGNORE
A colon-separated list of patterns defining the set of
filenames to be ignored by pathname expansion. If a file-
name matched by a pathname expansion pattern also matches
one of the patterns in GLOBIGNORE, it is removed from the
list of matches.
答え2
xargs
あなたの友達です!そうでない場合は、find
助けることもできます。
xargs
、find ... -exec
または拡張パターン マッチングを使用した 4 つのアプローチを次に示します。
xargs
経由しls
て使用grep
ls | grep -v Repetitive.log | xargs tail -f
xargs
経由して使用find
find . -maxdepth 1 ! -name Repetitive.log | xargs tail -f
引数find
と一緒に使用する-exec
find . -maxdepth 1 ! -name Repetitive.log -exec tail -f {} \;
拡張パターンマッチングを使用するbash
素晴らしい回答です。https://stackoverflow.com/a/19429723/1862762。
shopt -s extglob
tail -f /directory/of/logfiles/!(Repetitive.log)
注記
このタスクでは、それぞれのファイル名でタグ付けされたxargs
出力を提供する 方法の方が好ましいでしょう。と を使用すると、より直感的で覚えやすいようです。tail
ls
grep