LoginSignup
0
4

More than 5 years have passed since last update.

bash 小技

Posted at

既にご存知とは思いますが・・業務で自分がよく使う小技を紹介させて頂きます

1. ファイル名の末尾に .bak をつけたバックアップファイルを作る (ブレース展開)

$ cp -a example_file{,.bak}

2. 直前のディレクトリに移動

$ cd -

3, 直前のコマンドを root で実行

$ sudo !!

長いコマンドを打って Permission deneid と言われた時などに・・

4. テンポラリファイル作らずにファイルを比較 (プロセス置換)

$ diff <(sort file1) <(soft file2)

iptables の設定の確認 # diff <(iptables-save) /etc/sysconfig/iptables とかでよく使います

5. hisotry から番号を指定して実行

$ !47

6. ASCII 文字コード表

$ man ascii

7. 自分のグローバル IP を知る

$ curl ifconfig.me

8. 直近のコマンドの最後の引数

$ cd !$

例えば何かのファイルを移動して、その移動先に移動して何かしたい時とかに使っています
$ mv example_file ../../../
$ cd !$

9. 末尾から最短一致

${path%/*}

ディレクトリ名を取得する時とかに
dirname ${hoge}でもいいかもしれない

10. 先頭から最長一致

${path##*/}

ファイル名を取得する時とかに
basename ${path} でもいいかもしれない

0
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
0
4