Linux コマンド・チートシート

ここでは,使用頻度の高い Linux コマンドについて説明します.

find

  • 特定拡張子のファイル内検索
    $ find . -type f -name '*.cpp' | xargs grep '#include <vector>' -n
    • -type f: 属性がファイルの物を対象とする.
    • -name: ファイル名を指定するオプション.'*.cpp' は,\*.cpp としてもよい.
    • -n: 行数を表示するオプション
  • 複数拡張子のファイル内検索
    $ find . -type f \( -name '*.cpp' -o -name '*.hpp' \) | xargs grep '#include ' -n
    -o: は -or としてもよい[1]
    • @ コピペ用
      *.c, *.cpp, *.h, *.hpp
      $ find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) | xargs grep '#include ' -n
  • システム全体からの探索
    $ find / -type f 2>/dev/null | grep hogehoge
    • -type f: ファイルのみ検索
    • 2>/dev/null: Permission denided を無視

イベントのリアルタイム表示

$ tail -f -n1 /var/log/syslog
$ tail -f -n1 /var/log/syslog | grep IO_PAGE_FAULT

ログの見方

$ sudo cat /var/log/syslog | grep ERROR
$ cat /var/log/kern.log | grep ERROR

References

[1] findコマンドで複数の名前条件を指定 external_link - 2020.06.28 閲覧.