LoginSignup
4
4

More than 5 years have passed since last update.

個人的によく使うLinuxコマンドメモ

Last updated at Posted at 2018-10-09

プログラムの実行結果のログを保存

# 標準出力をリダイレクトで保存(リダイレクトはデフォルトで1が設定)
$ ./program > program.log
$ ./program 1> program.log

# 標準出力と標準エラーを分けて保存
$ ./program 1> program.log 2> program_err.log

# 標準出力と標準エラーを両方とも保存
$ ./program > program.log 2>&1

ssh接続等でログアウトしてもコマンドをバックグラウンドで実行し続ける

# バックグラウンドで実行しログ(標準出力)を保存
$ nohup ./program > program.log &

# バックグラウンドで実行しログ(標準出力と標準エラー)を分けて保存
$ nohup ./program 1> program.log 2> program_err.log &

実行中のプログラムのログを表示

# ログを出力
$ tail program.log

# ログをリアルタイムで出力
$ tail -f -n 10 program.log
$ tailf program.log

# 監視モードで起動( Ctrl+Cで普通のlessに戻り、qで終了 )
$ less +F program.log

テキストの先頭から任意のサイズで切り取る

$ head -c 1024 a.txt > a1024.txt

# 環境によっては使えないかも
$ head -c 1k a.txt > a1k.txt
$ haad -c 1m a.txt > a1m.txt

実行中のプロセスの検索

$ ps aux | grep 検索したい文字列
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4