LoginSignup
4
3

More than 3 years have passed since last update.

よく使うワンライナー

Last updated at Posted at 2016-09-13

Linuxでよく使うコマンド集
Linxuを利用するにあたって、よく使うコマンドや陥りやすい罠など、整理します。

サーバのリソースを取得する

vmstat

CPU使用率、メモリの仕様状況等を取得するためのコマンド

vmstat 1 | awk '{print strftime("%y/%m/%d %H:%M:%S"), $0}'

但し、そのままファイル等にリダイレクトする場合は、awkがキャッシュしてしまうので、タイムラグが発生します。
以下の通りにすることで、回避可能

vmstat 1 | awk '{print strftime("%y/%m/%d %H:%M:%S"), $0}{ system(":") }' > vmstat.log

ファイルのいらないところを除外する

CSVファイルとか、他システムの連携ファイルとか、ヘッダーや、フッターいらないケースが多々あると思います。

ヘッダーを除外する

cat ファイル名 | awk 'NR > 1 {print}'

フッターを除外する

cat ファイル名 | sed -e '$d'

ヘッダーとフッターを除外する

cat ファイル名 | sed -e '$d' | awk 'NR > 1 {print}'
4
3
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
3