五周第三次课(1月10日)
8.1 shell介绍
8.2 命令历史
8.3 命令补全和别名
8.4 通配符
8.5 输入输出重定向
history命令:
用于显示指定数目的指令命令,读取历史命令文件中的目录到历史命令缓冲区和将历史命令缓冲区中的目录写入命令文件。
该命令单独使用时,仅显示历史命令,在命令行中,可以使用符号!执行指定序号的历史命令。例如,要执行第2个历史命令,则输入!2。
历史命令是被保存在内存中的,当退出或者登录shell时,会自动保存或读取。在内存中,历史命令仅能够存储1000条历史命令,该数量是由环境变量HISTSIZE进行控制。
语法
history(选项)(参数)
选项
-c:清空当前历史命令;
-a:将历史命令缓冲区中命令写入历史命令文件中;
-r:将历史命令文件中的命令读入当前历史命令缓冲区;
-w:将当前历史命令缓冲区命令写入历史命令文件中。
参数
n:打印最近的n条历史命令。
实例
使用history命令显示最近使用的10条历史命令,输入如下命令:
[root@localhost ~]# history 10
92 ls
93 cd ..
94 ls
95 exit
96 ls -a
97 cd .ssh/
98 ls
99 cat known_hosts
100 exit
101 history 10
[BEGIN] 2018/1/10 21:11:47
Last login: Wed Jan 10 21:08:11 2018
[root@localhost ~]# yum list |grep zsh
autojump-zsh.noarch 22.3.0-3.el7 epel
zsh.x86_64 5.0.2-28.el7 base
zsh-html.x86_64 5.0.2-28.el7 base
zsh-lovers.noarch 0.9.0-1.el7 epel
[root@localhost ~]# yum list |grep ksh
ksh.x86_64 20120801-34.el7 base
mksh.x86_64 46-5.el7 base
python-XStatic-Rickshaw.noarch 1.5.0.0-4.el7 epel
python-moksha-common.noarch 1.2.3-2.el7 epel
python-moksha-hub.noarch 1.5.3-2.el7 epel
python-moksha-wsgi.noarch 1.2.2-2.el7 epel
[root@localhost ~]# ls /root/.bash_history
/root/.bash_history
[root@localhost ~]# cat !$
cat /root/.bash_history
ls -l
chown :root /tmp/admin2
ls -l
chown-R root :root /tmp/admin2
chown -R root :root /tmp/admin2
chown -R root:root /tmp/admin2
ls -l
mv CentOS7-Base-163.repo CentOS7-Base-163.repo.123
yum clean all
yum repolist all
yum install zsh
mv CentOS7-Base-163.repo.123 CentOS7-Base-163.repo
yum repolist all
yum clean all
yum install zsh
yum install -y wget
ls
yum install -y epel-release
ls
yum list
yum list |grep epel
yum install zsh --downloadonly
ls /
ls /var/cache/yum/x86_64/7/updates/packages/
ls /var/cache/yum/x86_64/7/base/packages/
yum install zsh --downloadonly --downloaddir=/tmp/
ls /tmp/
yum install vim-enhanced --downloadonly --downloaddir=/tmp/
yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
ls /tmp/
cd
cd /usr/local/src/
ls
wget http://mirros.cnnic.cn/apache/httpd-2.2.32.tar.gz
wget http://mirros.cnnic.cn/apache/httpd-2.2.34.tar.gz
wget
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
ls
tar -zxvf httpd-2.2.34.tar.gz
ls
cd httpd-2.2.34
ls
more README
./configure --prefix=/usr/local/apache2
echo $?
yum install gcc
./configure --prefix=/usr/local/apache2
echo $?
make
echo $?
make install
echo $?
ls
ls /usr/local/apache2/
ip add
init 0
[root@localhost ~]# history
3 ls -l
4 chown-R root :root /tmp/admin2
5 chown -R root :root /tmp/admin2
6 chown -R root:root /tmp/admin2
7 ls -l
8 touch 11.txt
9 ls -l 11.txt
10 mkdir 123
11 ls -ld 123
12 umask
13 umask 002
14 touch 21.txt
15 ls -l 21.txt
990 make
991 echo $?
992 make install
993 echo $?
994 ls
995 ls /usr/local/apache2/
996 ip add
997 init 0
998 yum list |grep zsh
999 yum list |grep ksh
1000 ls /root/.bash_history
1001 cat /root/.bash_history
1002 history
[root@localhost ~]# echo $HISTSIZE
1000
[root@localhost ~]# vi /etc/profile
[root@localhost ~]# echo $HISTSIZE
1000
[root@localhost ~]# source /etc/profile
[root@localhost ~]# echo $HISTSIZE
10000
[root@localhost ~]# history
7 ls -l
8 touch 11.txt
9 ls -l 11.txt
10 mkdir 123
11 ls -ld 123
12 umask
13 umask 002
14 touch 21.txt
15 ls -l 21.txt
16 mkdir 332
17 ls -ld 332
18 umask 003
19 umask
20 ls
21 touch 1.txt
22 ls -l
23 ls -l
24 chattr +i 1.txt
25 vi 1.txt
26 head -n2 /etc/passwd > 1
1000 ls /root/.bash_history
1001 cat /root/.bash_history
1002 history
1003 echo $HISTSIZE
1004 vi /etc/profile
1005 echo $HISTSIZE
1006 source /etc/profile
1007 echo $HISTSIZE
1008 history
[root@localhost ~]# vim /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# chattr +a ~/.bash_history
[root@localhost ~]# yum install -y bash-completion
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 7.2 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 868 kB 00:00:00
(2/2): epel/x86_64/primary_db | 6.2 MB 00:00:01
Loading mirror speeds from cached hostfile
* epel: mirrors.sohu.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 bash-completion.noarch.1.2.1-6.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================================
Package 架构 版本 源 大小
================================================================================================
正在安装:
bash-completion noarch 1:2.1-6.el7 base 85 k
事务概要
================================================================================================
安装 1 软件包
总下载量:85 k
安装大小:259 k
Downloading packages:
bash-completion-2.1-6.el7.noarch.rpm | 85 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : 1:bash-completion-2.1-6.el7.noarch 1/1
验证中 : 1:bash-completion-2.1-6.el7.noarch 1/1
已安装:
bash-completion.noarch 1:2.1-6.el7
完毕!
[root@localhost ~]# exit
登出
[BEGIN] 2018/1/10 22:13:22
Last login: Wed Jan 10 21:11:32 2018 from 192.168.183.1
[root@localhost ~]# history
1 2018/01/10 22:13:22ls -l
2 2018/01/10 22:13:22chown :root /tmp/admin2
3 2018/01/10 22:13:22ls -l
4 2018/01/10 22:13:22chown-R root :root /tmp/admin2
5 2018/01/10 22:13:22chown -R root :root /tmp/admin2
6 2018/01/10 22:13:22chown -R root:root /tmp/admin2
7 2018/01/10 22:13:22ls -l
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‘
]0;root@localhost:~[root@localhost ~]#