顯示歷史命令 後10個shell
[root@yong-02 ~]# history |tail 327 ls 328 cd apr-util-1.6.1 329 ls /usr/local/apache2/ 330 cd 331 ls 332 zsh 333 eix 334 yum list | grep zsh 335 history 336 history |tail
[root@yong-02 ~]# echo $HISTSIZE 1000
歷史命令保存在用戶家目錄的.bash_history文件中apache
清空內存中的歷史記錄;不會清除.bash_history文件中的記錄。vim
[root@yong-02 ~]# history -c [root@yong-02 ~]# history 1 history [root@yong-02 ~]# head -10 .bash_history ifconfig ls ls /tmp df -h ls -toot ls /root dhclient ifconfig ls ifconfig
[root@yong-02 ~]# vim /etc/profile 搜索HISTSIZE 默認值是1000,能夠修改爲5000條,而後按esc,:wq 保存退出。 而後運行命令:source /etc/profile [root@yong-02 ~]# source /etc/profile [root@yong-02 ~]# echo $HISTSIZE 5000
在配置文件/etc/profile中修改,在HISTSIZE=5000下面,添加一行HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
bash
[root@yong-02 ~]# vim /etc/profile [root@yong-02 ~]# source /etc/profile [root@yong-02 ~]# history 1 2018/04/19 22:37:56 history 2 2018/04/19 22:38:18 head -10 .bash_profile 3 2018/04/19 22:38:28 head -10 .bash_history 4 2018/04/19 22:39:24 vim /etc/profie 5 2018/04/19 22:39:38 vim /etc/profile 6 2018/04/19 22:41:23 source /etc/profile 7 2018/04/19 22:41:37 echo $HISTSIZE 8 2018/04/19 22:42:15 vim /etc/profile 9 2018/04/19 22:42:53 source /etc/profile 10 2018/04/19 22:43:07 history
[root@yong-02 ~]# chattr +a .bash_history [root@yong-02 ~]# lsattr .bash_history -----a---------- .bash_history
[root@yong-02 ~]# lsattr .bash_history -----a---------- .bash_history [root@yong-02 ~]# !! lsattr .bash_history -----a---------- .bash_history
[root@yong-02 ~]# history 1 2018/04/19 22:37:56 history 2 2018/04/19 22:38:18 head -10 .bash_profile 3 2018/04/19 22:38:28 head -10 .bash_history 4 2018/04/19 22:39:24 vim /etc/profie 5 2018/04/19 22:39:38 vim /etc/profile 6 2018/04/19 22:41:23 source /etc/profile 7 2018/04/19 22:41:37 echo $HISTSIZE 8 2018/04/19 22:42:15 vim /etc/profile 9 2018/04/19 22:42:53 source /etc/profile 10 2018/04/19 22:43:07 history 11 2018/04/19 22:43:56 chattr +a .bash_history 12 2018/04/19 22:44:12 lsattr .bash_history 13 2018/04/19 22:45:07 history 14 2018/04/19 22:45:25 ls 15 2018/04/19 22:45:28 pws 16 2018/04/19 22:45:31 pwd 17 2018/04/19 22:45:48 history [root@yong-02 ~]# !14 ls anaconda-ks.cfg a.txt c.txt multi-user.target reboot.target apr-util-1.6.1.tar.bz2 b.txt graphical.target poweroff.target rescue.target
[root@yong-02 ~]# !pw pwd /root
[root@yong-02 ~]# yum install -y bash-completion 重啓服務器 reboot
[root@yong-02 ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@yong-02 ~]# cat .bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
[root@yong-02 ~]# ls /etc/profile.d/ 256term.csh colorgrep.csh colorls.sh less.csh vim.sh 256term.sh colorgrep.sh lang.csh less.sh which2.csh bash_completion.sh colorls.csh lang.sh vim.csh which2.sh
vim/etc/profile.d/colorls.sh 服務器
[root@yong-02 test]# ls *.txt 11.txt 1.txt 23.txt 2.txt 3.txt ab.txt a.txt b.txt [root@yong-02 test]# ls *txt 11.txt 1.txt 23.txt 2.txt 3.txt ab.txt a.txt b.txt [root@yong-02 test]# ls *txt* 11.txt 1.txt 23.txt 2.txt 3.txt ab.txt a.txt b.txt cc.txt.bak
[root@yong-02 test]# ls ?.txt 1.txt 2.txt 3.txt a.txt b.txt
[root@yong-02 test]# ls [0-3].txt 1.txt 2.txt 3.txt [root@yong-02 test]# ls [123].txt 1.txt 2.txt 3.txt [root@yong-02 test]# ls [23].txt 2.txt 3.txt [root@yong-02 test]# ls [a-z].txt a.txt b.txt [root@yong-02 test]# ls [az].txt a.txt [root@yong-02 test]# ls [0-9a-z].txt 1.txt 2.txt 3.txt a.txt b.txt
[root@yong-02 test]# ls {1,3}.txt 1.txt 3.txt [root@yong-02 test]# ls {1,3,2,a}.txt 1.txt 2.txt 3.txt a.txt
[root@yong-02 test]# echo "aabbcc123" >1.txt [root@yong-02 test]# cat 1.txt aabbcc123
[root@yong-02 test]# echo "56789" >>1.txt [root@yong-02 test]# cat 1.txt aabbcc123 56789
[root@yong-02 test]# ls ccc.txt 2>2.txt [root@yong-02 test]# cat 2.txt ls: 沒法訪問ccc.txt: 沒有那個文件或目錄
[root@yong-02 test]# ls bbb.txt 2>>2.txt [root@yong-02 test]# cat 2.txt ls: 沒法訪問ccc.txt: 沒有那個文件或目錄 ls: 沒法訪問bbb.txt: 沒有那個文件或目錄
[root@yong-02 test]# ls 1.txt aaa.txt &>3.txt [root@yong-02 test]# cat 3.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 1.txt
[root@yong-02 test]# ls 1.txt aaa.txt &>>3.txt [root@yong-02 test]# cat 3.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 1.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 1.txt
[root@yong-02 test]# ls 23.txt aaa.txt > 1.txt 2>2.txt [root@yong-02 test]# cat 1.txt 23.txt [root@yong-02 test]# cat 2.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄
[root@yong-02 test]# wc -l </etc/passwd 25 [root@yong-02 test]# 2.txt < 3.txt -bash: 2.txt: 未找到命令 左邊只能是命令,不能是文件。