顯示歷史命令linux
[root@linux-128 ~]# history 1 mkdir /tmp/222 2 rmdir /tmp/111/ /tmp/222/ . . . 995 echo $? 996 ls /usr/local/apache2/ 997 init 0 998 ls ./.bash_history 999 vim ./.bash_history 1000 history
歷史命令保存在用戶家目錄的.bash_history文件中shell
清空內存中的歷史記錄;不會清除.bash_history文件中的記錄。apache
[root@linux-128 ~]# history -c [root@linux-128 ~]# history 2 history [root@linux-128 ~]# head -10 .bash_history mkdir /tmp/222 rmdir /tmp/111/ /tmp/222/ ls lsls tmp ls /tmp mkdir /tmp/111 mkdir /tmp/222 ls ls /tmp rmdir /tmp/111/ /tmp/222/
[root@linux-128 ~]# vim /etc/profile 搜索HISTSIZE 默認值是1000,能夠修改爲5000條,而後按esc,:wq 保存退出。 而後運行命令:source /etc/profile [root@linux-128 ~]# source /etc/profile [root@linux-128 ~]# echo $HISTSIZE 5000
在配置文件/etc/profile中修改,在HISTSIZE=5000下面,添加一行HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
vim
[root@linux-128 ~]# vim /etc/profile [root@linux-128 ~]# source /etc/profile [root@linux-128 ~]# history 2 2017/11/15 21:49:44 history 3 2017/11/15 21:50:20 head -10 .bash_history 4 2017/11/15 21:55:05 vim /etc/profile 5 2017/11/15 21:57:52 source /etc/prfile 6 2017/11/15 21:58:04 source /etc/profile 7* 2017/11/15 21:58:16 echo $HIST 8 2017/11/15 22:01:02 vim /etc/profile 9 2017/11/15 22:03:49 history 10 2017/11/15 22:03:57 source /etc/profile 11 2017/11/15 22:03:59 history 12 2017/11/15 22:04:20 vim /etc/profile 13 2017/11/15 22:05:14 source /etc/profile 14 2017/11/15 22:05:17 history
[root@linux-128 ~]# chattr +a .bash_history
[root@linux-128 ~]# pwd /root [root@linux-128 ~]# !! pwd /root
[root@linux-128 ~]# history 2 2017/11/15 21:49:44 history 3 2017/11/15 21:50:20 head -10 .bash_history 4 2017/11/15 21:55:05 vim /etc/profile 5 2017/11/15 21:57:52 source /etc/prfile 6 2017/11/15 21:58:04 source /etc/profile 7* 2017/11/15 21:58:16 echo $HIST 8 2017/11/15 22:01:02 vim /etc/profile 9 2017/11/15 22:03:49 history 10 2017/11/15 22:03:57 source /etc/profile 11 2017/11/15 22:03:59 history 12 2017/11/15 22:04:20 vim /etc/profile 13 2017/11/15 22:05:14 source /etc/profile 14 2017/11/15 22:05:17 history 15 2017/11/15 22:07:56 chattr +a .bash_history 16 2017/11/15 22:08:10 vim .bash_history 17 2017/11/15 22:09:25 pwd 18 2017/11/15 22:10:31 history [root@linux-128 ~]# !17 pwd /root
[root@linux-128 ~]# !pw pwd /root
[root@linux-128 ~]# yum install -y bash-completion 重啓服務器 reboot
[root@linux-128 ~]# 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'
# .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@linux-128 ~]# 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 root@linux-128 ~]# vim /etc/profile.d/colorls.sh
[root@linux-128 ~]# ls *txt 11.txt 1a.txt 23.txt 321.txt ab.txt a.txt b.txt 工號.txt [root@linux-128 ~]# ls 1* 11.txt 11.txt.bak 12 1a.txt 1.log 123: [root@linux-128 ~]# ls *1* 11.txt 11.txt.bak 12 1a.txt 1.log 321.txt 321.txt.bak 123: [root@linux-128 ~]# ls *a* 11.txt.bak 1a.txt 321.txt.bak ab.txt anaconda-ks.cfg a.txt
[root@linux-128 ~]# ls ?.txt a.txt b.txt
[root@linux-128 ~]# ls [0-3].txt 1.txt 2.txt [root@linux-128 ~]# ls [a-z].txt a.txt b.txt [root@linux-128 ~]# ls [0-9a-zA-Z].txt 1.txt 2.txt a.txt b.txt
[root@linux-128 ~]# ls {1,2}.txt 1.txt 2.txt [root@linux-128 ~]# ls {1,2,3}.txt ls: 沒法訪問3.txt: 沒有那個文件或目錄 1.txt 2.txt
[root@linux-128 ~]# echo "112233">1.txt [root@linux-128 ~]# cat 1.txt 112233
[root@linux-128 ~]# echo "aabbcc">>1.txt [root@linux-128 ~]# cat 1.txt 112233 Aabbcc
[root@linux-128 ~]# ls aaa.txt 2>2.txt [root@linux-128 ~]# cat 2.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄
[root@linux-128 ~]# ls aaa.txt 2>>2.txt [root@linux-128 ~]# cat 2.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 ls: 沒法訪問aaa.txt: 沒有那個文件或目錄
[root@linux-128 ~]# ls 1.txt aaa.txt &> 1.txt [root@linux-128 ~]# cat 1.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 1.txt
[root@linux-128 ~]# ls 1.txt aaa.txt &>> 1.txt [root@linux-128 ~]# cat 1.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 1.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄 1.txt
[root@linux-128 ~]# ls 1.txt aaa.txt > 1.txt 2>2.txt [root@linux-128 ~]# cat 1.txt 1.txt [root@linux-128 ~]# cat 2.txt ls: 沒法訪問aaa.txt: 沒有那個文件或目錄
[root@linux-128 ~]# wc -l < /etc/passwd 27 左邊只能是命令,不能是文件。