Bash
「Linux」全般の話題というより、Bash シェル上で使うことの多いコマンドのチートシートがメイン。
目次
エンコードを変える
$ LANG='ja_JP.euc-JP'
$ LANG='ja_JP.UTF-8'
grep のオプション
# 基本 : カレントディレクトリ配下の全ファイルを対象に検索する
$ grep -inR '調べたいこと' .
# 以下だとサブディレクトリを調べてくれない
$ grep -inR '調べたいこと' ./*.md
# --include : 拡張子判定
$ grep -iRl img1 --include='*.java'
# --exclude : 除外 … Java と Class を除外
$ grep -iRl img_memo --exclude='*.class' --exclude='*.java'
-i:--ignore-case… 大文字小文字区別なし-l:--files-with-matches… ファイル名のみ出力-n:--line-number… 行番号を出力する-r:--recursive… サブディレクトリも対象にする-R:--dereference-recursive…-rと同様だがシンボリックリンクも辿る- オプションは分けても繋げても良い (
-i -R -l=-iRl)
EUC-JP なファイルを tail する (nkf を使う)
$ tail -f ./apache/logs/catalina.out | nkf -u -w
nkfで UTF-8 に対応させて出力させる-uは出力をバッファしないオプション
ファイル・ディスクリプタまとめ
command > /dev/null- 標準出力を捨てる
command 2> /dev/null- 標準エラー出力を捨てる
command > /dev/null 2>&1- 標準エラー出力の結果を標準出力にマージし、標準出力を捨てる
- 全て握りつぶすにはこうする
- 参考 : いい加減覚えよう。command > /dev/null 2>&1 の意味 - Qiita
tar コマンドのオプション
| tar | Action | Type | Options | Dest File | Source Files... | Alternative | |||
|---|---|---|---|---|---|---|---|---|---|
| tar | c | (--create) | (unspecified) | (= Tarball) | v f |
(--verbose) (--file) |
./dest.tar | ./source.txt ./sources/ | - |
| z | (--gzip) | ./dest.tar.gz | gzip | ||||||
| j | (--bzip2) | ./dest.tar.bz2 | bzip2 | ||||||
| J | (--xz) | ./dest.tar.xz | xz | ||||||
| a | (--auto-compress) | ./dest.tar.【Type】 | ※ GNU tar only | ||||||
| t | (--list) | (unspecified) | (= auto-detect) | ./dest.tar | - | - | |||
| x | (--extract) | (unspecified) | (= auto-detect) | ./dest.tar | - | - | |||
| z | (--gzip) | ./dest.tar.gz | gunzip | ||||||
| j | (--bzip2) | ./dest.tar.bz2 | bunzip2 | ||||||
| J | (--xz) | ./dest.tar.xz | unxz | ||||||