默认情况下,bash会在文件$HOME/.bash_history中存放多达500条命令记录。有时根据具体的系统不同,默认记录条数不同。系统中每个用户的主目录下都有一个这样的文件。
示例如下:
[root@localhost ithov]# ls -la
总用量&">nbsp;164 drwx------. 28 ithov ithov 4096 6月 18 16:18 . drwxr-xr-x. 5 root root 4096 6月 11 11:50 .. drwxrwxr-x. 2 ithov 500 4096 6月 8 16:34 .abrt -rw-------. 1 ithov ithov 106 6月 18 10:46 .bash_history -rw-r--r--. 1 ithov 500 18 2月 22 05:05 .bash_logout -rw-r--r--. 1 ithov 500 176 2月 22 05:05 .bash_profile -rw-r--r--. 1 ithov 500 124 2月 22 05:05 .bashrc drwxr-xr-x. 3 ithov 500 4096 6月 8 16:34 .cache drwxr-xr-x. 5 ithov 500 4096 6月 8 16:34 .config drwx------. 3 ithov 500 4096 6月 8 16:34 .dbus -rw-r--r--. 1 ithov ithov 31 6月 18 14:40 .dmrc -rw-------. 1 ithov 500 16 6月 8 16:34 .esd_auth drwx------. 4 ithov 500 4096 6月 18 14:40 .gconf drwx------. 2 ithov 500 4096 6月 18 16:32 .gconfd drwxr-xr-x. 6 ithov 500 4096 6月 8 16:43 .
gnome2 drwx------. 2 ithov ithov 4096 6月 8 16:43 .gnome2_private drwxrwxr-x. 3 ithov 500 4096 6月 8 16:34 .gnote drwx------. 2 ithov 500 4096 6月 18 14:40 .gnupg drwxrwxr-x. 2 ithov 500 4096 6月 8 16:34 .gstreamer-0.10 -rw-rw-r--. 1 ithov ithov 190 6月 18 14:40 .gtk-bookmarks drwx------. 2 ithov 500 4096 6月 8 16:34 .gvfs -rw-------. 1 ithov 500 2484 6月 18 14:40 .ICEauthority -rw-r--r--. 1 ithov ithov 871 6月 18 16:32 .imsettings.log drwxr-xr-x. 3 ithov 500 4096 6月 8 16:34 .local drwxr-xr-x. 5 ithov 500 4096 6月 8 16:43 .
mozilla drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 .nautilus drwx------. 2 ithov ithov 4096 6月 8 16:34 .pulse -rw-------. 1 ithov 500 256 6月 8 16:34 .pulse-cookie -rw-------. 1 ithov ithov 218 6月 10 11:13 .recently-used.xbel drwx------. 2 ithov 500 4096 6月 8 16:34 .ssh -rw-------. 1 ithov ithov 2318 6月 18 16:32 .xsession-errors -rw-------. 1 ithov ithov 2133 6月 18 10:46 .xsession-errors.old drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 公共的 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 模板 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 视频 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 图片 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 文档 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 下载 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:34 音乐 drwxr-xr-x. 2 ithov 500 4096 6月 8 16:44 桌面
为了系统的安全,在此强烈建议用户限制该文件的大小。用户可以编辑/etc/profile文件,修改其中的选项如下:
HISTFILESIZE=30 或 HISTSIZE=30
这样就将记录的命令条数减少到30条
示例:
[root@localhost ithov]# cat /etc/profile
# /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi esac } if [ -x /usr/bin/id ]; then if [ -z "$EUID" ]; then # ksh workaround EUID=`id -u` UID=`id -ru` fi USER="`id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" fi # Path manipulation if [ "$EUID" = "0" ]; then pathmunge /sbin pathmunge /usr/sbin pathmunge /usr/local/sbin else pathmunge /usr/local/sbin after pathmunge /usr/sbin after pathmunge /sbin after fi HOSTNAME=`/bin/hostname 2>/dev/null` HISTSIZE=1000 if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth else export HISTCONTROL=ignoredups fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL # By default, we want umask to get set. This sets it for login shell # Current threshold for system reserved uid/gids is 200 # You could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null 2>&1 fi fi done unset i unset -f pathmunge