LoginSignup
54
54

More than 5 years have passed since last update.

bash_historyを便利に使う

Last updated at Posted at 2014-05-14

historyコマンドに関して

historyコマンドはよく使ってたけど
最近ちょっと設定するだけでもっと便利に使える事を知りました
まず基本的な事として、historyの出力結果から
!を先頭に付与して実行する事でhistoryのコマンドを実行出来ます。

$ history
  .
  .
  498  rails console
  499  ls
  500  cd
  501  ls
  502  history
  503  pwd
  504  cd srvadmin/
  505  history
$ !498
rails console
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1
Loading development environment (Rails 4.0.3)
irb(main):001:0>

hisrotyに記憶するコマンドの数を増やす

centOSではデフォルトで1000件?っぽいですが増減する事が可能です
~/.bashrcに下記を記述


export HISTSIZE=2000

これでhistoryが2000件になります。
ある程度増やしても動作が重くなったりしないので
思い切って増やしておくと後で救われる時がたまーにあります。

重複するコマンドを取り除きたい

lsコマンドやpwdコマンド等、同じコマンドに関しては
重複を取り除いて履歴を持つ事が出来ます。
~/.bashrcに下記を記述


export HISTCONTROL=ignoredups 

Screen使っても履歴を共有したい(bashの場合)

Screenを利用して作業していると
A画面とB画面でコマンドが共有されません。
対象サーバの~/.bashrcに下記を追加する事により
historyが共有出来るようになります。


function share_history {
    history -a
    history -c
    history -r
}
PROMPT_COMMAND='share_history'
shopt -u histappend
export HISTSIZE=9999

参考
http://iandeth.dyndns.org/mt/ian/archives/000651.html
http://takuya-1st.hatenablog.jp/entry/20090828/1251474360

54
54
1

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
54
54