命令历史是保存在/root/.bash_history 里面的,能够cat进行查看。linux
默认命令历史保存最大存1000条历史命令。能够echo $HISTSIZE进行查看数量。这个数量是环境变量控制的,能够更改。shell
[root@localhost ~]# echo $HISTSIZE 1000
vi /etc/profile 找到 HOSTNAME=`/usr/bin/hostname 2>/dev/null` HISTSIZE=1000 ------------若是以为1000条不够能够改为5000----------- if [ "$HISTCONTROL" = "ignorespace" ] ; then
更改以后必须退出一下终端从新进或者source /etc/profile 才会更改vim
[root@localhost ~]# echo $HISTSIZE 1000 [root@localhost ~]# source /etc/profile [root@localhost ~]# echo $HISTSIZE 5000
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"bash
[root@localhost ~]# history 1 ls 2 ls /etc/passwd 3 cat /etc/passwd 4 [root@localhost ~]# cat /etc/passwd 5 root:x:0:0:root:/root:/bin/bash 6 bin:x:1:1:bin:/bin:/sbin/nologin 7 daemon:x:2:2:daemon:/sbin:/sbin/nologin 8 adm:x:3:4:adm:/var/adm:/sbin/nologin 9 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
从新赋值以后ssh
[root@localhost ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S " [root@localhost ~]# history 1 2017/08/30 19:20:18 ls 2 2017/08/30 19:20:18 ls /etc/passwd 3 2017/08/30 19:20:18 cat /etc/passwd 4 2017/08/30 19:20:18 [root@localhost ~]# cat /etc/passwd 5 2017/08/30 19:20:18 root:x:0:0:root:/root:/bin/bash 6 2017/08/30 19:20:18 bin:x:1:1:bin:/bin:/sbin/nologin 7 2017/08/30 19:20:18 daemon:x:2:2:daemon:/sbin:/sbin/nologin 8 2017/08/30 19:20:18 adm:x:3:4:adm:/var/adm:/sbin/nologin
这时候再打开一个新的终端,这个环境变量是不生效的。工具
若是想让此环境变量全局生效,须要编辑 /etc/profile把HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "加到里面学习
fi HOSTNAME=`/usr/bin/hostname 2>/dev/null` HISTSIZE=5000 HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" if [ "$HISTCONTROL" = "ignorespace" ] ; then export HISTCONTROL=ignoreboth
source /etc/profile后生效spa
chattr +a ~/.bash_history 设置了这个权限只能追加不能删除rest
表示运行最后一条历史命令code
指定运行历史行数命令
表示命令历史里面最后一次输入这个命令的命令
[root@localhost ~]# alias restartnet='systemctl restart network.service' [root@localhost ~]# restartnet [root@localhost ~]# 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 restartnet='systemctl restart network.service' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' [root@localhost ~]#
alias 存在用户家目录下的 .bashrc文件里。
还有一些存在 /etc/profile.d/下面
unalias 取消自定义别名
[root@localhost ~]# ls 111 1eer 1.txt 2.txt anaconda-ks.cfg erwe [root@localhost ~]# ls *.txt 1.txt 2.txt [root@localhost ~]# [root@localhost ~]# ls 1* 1eer 1.txt 111: [root@localhost ~]# ls *1* 1eer 1.txt 111: [root@localhost ~]#
问号表示任意一个字符
[root@localhost ~]# ls ?.txt 1.txt 2.txt [root@localhost ~]# ls *.txt 1.txt 2.txt bbcc.txt bb.txt [root@localhost ~]#
选择范围
[root@localhost ~]# ls [123].txt 1.txt 2.txt [root@localhost ~]# ls [0-9].txt 1.txt 2.txt [root@localhost ~]# ls [1].txt 1.txt [root@localhost ~]# ls [2].txt 2.txt [root@localhost ~]#
也是选择范围,跟[]差很少,可是中间有逗号
[root@localhost ~]# ls {1,2}.txt 1.txt 2.txt [root@localhost ~]#
把>前面的内容删除掉重定向到后面内容去。
把>>前面的内容追加到后面内容去。
表示把运行错误的信息定向到一个文件里
[root@localhost ~]# fddd -bash: fddd: 未找到命令 [root@localhost ~]# fddd 2> 1.txt [root@localhost ~]# cat 1.txt -bash: fddd: 未找到命令
错误追加剧定向
错误和正确都有的输出重定向
[root@localhost ~]# ls [12].txt asffsfs.txt &> 1.txt [root@localhost ~]# cat 1.txt ls: 没法访问asffsfs.txt: 没有那个文件或目录 1.txt 2.txt [root@localhost ~]#
输入重定向
把<右边的文件内容输入到<左边的命令里面去
[root@localhost ~]# wc -l < 1.txt 3 [root@localhost ~]#
[root@localhost ~]# vim 1.txt [1]+ 已中止 vim 1.txt [root@localhost ~]# vim 2.txt [2]+ 已中止 vim 2.txt [root@localhost ~]# jobs [1]- 已中止 vim 1.txt [2]+ 已中止 vim 2.txt [root@localhost ~]#
[root@localhost ~]# echo $a$bb 1 [root@localhost ~]# echo '$a$bb' $a$bb
[root@localhost ~]# pstree systemd─┬─NetworkManager───2*[{NetworkManager}] ├─agetty ├─auditd───{auditd} ├─chronyd ├─crond ├─dbus-daemon───{dbus-daemon} ├─firewalld───{firewalld} ├─lvmetad ├─master─┬─pickup │ └─qmgr ├─polkitd───5*[{polkitd}] ├─rsyslogd───2*[{rsyslogd}] ├─sshd───sshd───bash─┬─pstree │ └─2*[vim] ├─systemd-journal ├─systemd-logind ├─systemd-udevd ├─tuned───4*[{tuned}] └─vmtoolsd───{vmtoolsd} [root@localhost ~]#