実際の業務で個人的によく使うものや、過去に使ったトリッキーなものをまとめてみます。
空のファイルを作成
|
1 |
touch ファイル名 |
連番で100個ファイル作成
|
1 2 |
# test-001, test-002, ... , test-100 touch test-{001..100} |
ディレクトリ作って中に同時にcd
|
1 |
mkdir ディレクトリ名;cd $_ |
$_ で直前のコマンドの引数を参照できます。
一つ前のディレクトリに戻る
|
1 |
cd - |
ホームから深い階層間を飛び回るときなどに重宝。
指定したプロセスが動いているか確認
|
1 2 |
# mysqlの場合 ps aux | grep mysql | grep -v grep |
大きいファイルランキング
|
1 2 |
# /var/log以下にあるファイルを大きい順に10個表示 sudo ls -la $(sudo find /var/log -type f) | sort -nr -k5 | head -10 | awk '{print NR,$9,":",$5/1024/1024,"MB" }' |
出力結果
|
1 2 3 4 5 6 7 8 9 10 |
1 /var/log/httpd/rewrite_log-20150823 : 5321.79 MB 2 /var/log/httpd/rewrite_log-20150809 : 5250.85 MB 3 /var/log/httpd/rewrite_log-20150816 : 5136.87 MB 4 /var/log/httpd/rewrite_log-20150802 : 4739.55 MB 5 /var/log/httpd/example.com-access_log-20150823 : 989.039 MB 6 /var/log/httpd/example.com-access_log-20150809 : 976.317 MB 7 /var/log/httpd/example.com-access_log-20150816 : 967.496 MB 8 /var/log/httpd/example.com-access_log-20150802 : 879.911 MB 9 /var/log/httpd/rewrite_log-20151122 : 263.879 MB 10 /var/log/httpd/rewrite_log : 262.697 MB |
ファイルの内容を再帰検索
|
1 2 |
# /etc以下の AuthorizedKeys が含まれるファイルを再帰検索 find /etc -type f -print0 2>/dev/null | xargs -0 grep --color=AUTO -Hn 'AuthorizedKeys' 2>/dev/null |
該当箇所のファイルパス、行番号、該当箇所を色付きで出力します。見やすくてオススメ。
複数のファイルからユニークな行だけを抽出してソート
|
1 |
uniq -u <(sort file1 file2 file3 ...) |
使用例
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cat text1 # one # liner # works cat text2 # working # one # liner uniq -u <(sort text*) # working # works |
また随時追加していきます


