.bashrc編集(historyコマンドの保存行数増加とlsコマンド色つけ)

2024/02/06
Debian 12のrootで“.bashrc”を編集して,使い勝手を改善する.
初期状態は以下の状態.コメントに色々書いてあるのでよく読む.
root@server:~# cat .bashrc_org
# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "$(dircolors)"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
root@server :~#
コメントを参考にlsの実行結果の色づけを有効にする.
また,historyコマンドの記録行数を増やす設定行も追加する(これは別途調べた).
いつも通りdiffで編集箇所を示す*1
root@server:~# diff -u .bashrc_org .bashrc
--- .bashrc_org 2024-01-17 09:15:12.440470628 +0900
+++ .bashrc     2024-01-17 09:13:29.503977575 +0900
@@ -6,13 +6,15 @@
 # umask 022

 # You may uncomment the following lines if you want `ls' to be colorized:
-# export LS_OPTIONS='--color=auto'
-# eval "$(dircolors)"
-# alias ls='ls $LS_OPTIONS'
-# alias ll='ls $LS_OPTIONS -l'
-# alias l='ls $LS_OPTIONS -lA'
+export LS_OPTIONS='--color=auto'
+eval "$(dircolors)"
+alias ls='ls $LS_OPTIONS'
+alias ll='ls $LS_OPTIONS -l'
+alias l='ls $LS_OPTIONS -lA'
 #
 # Some more alias to avoid making mistakes:
 # alias rm='rm -i'
 # alias cp='cp -i'
 # alias mv='mv -i'
+HISTSIZE=10000
+HISTFILESIZE=20000
root@server:~#
なお,historyコマンドの履歴の実体はrootであれば,“/root/.bash_history”である.
HISTFILESIZEでこのファイルに記録される履歴数を設定する.
HISTSIZEはあるログイン作業中にキャッシュされる履歴数.ログアウト時に“/root/.bash_history”へ追記される.
今回の設定値はどちらも多めだが,システムの性能に余力があるので特に問題ないと思う.

*1 : “bashrc_org”の方が新しいですが,これは“.bashrc”を直接編集保存してしまい,後からオリジナル記述のファイルとして“.bashrc_org”を作成したためです.