LoginSignup
9
6

More than 5 years have passed since last update.

便利系ワンライナー

Last updated at Posted at 2015-03-03

たまに使うけど忘れがちなワンライナーをメモ代わりに残しておく。
随時更新。

[実行環境]
・Linux
・bash
・awk

圧縮されたログの合計サイズを出力する

$ du -s ./access_log-*.gz | awk '{total+=$1} END {print total}'

ログの特定カラムの桁数TOP10を出す

ログをRDBのテーブルに突っ込みたいけど桁数が読めない、という場合に便利

# 5番目のカラムの桁数が知りたい場合(ファイルは空白orタブ区切りの前提)
$ cat access_log | awk '{len=length($5);print len}' | sort -nr | head -10

MySQLのセッションのコマンド別件数(Query,Sleepなど)を知る

QueryはStateによって状態が大きく違うので、別々に集計する。

$ mysql -uroot -p -B -N -e 'show processlist' | awk -F "\t" '{if($5=="Query") {print "Query:"$7} else {print $5}}'| sort | uniq -c
9
6
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
9
6