[toc]linux
8.1 shell介绍shell
8.2 命令历史vim
8.3 命令补全和别名bash
8.4 通配符ssh
8.5 输入输出重定向rest
shell是一个命令解释器,提供用户和机器之间的交互code
支持特定语法,好比逻辑判断、循环ip
每一个用户均可以有本身特定的shell内存
CentOS7默认shell为bash(Bourne Agin Shell)文档
还有zsh、ksh等
[root@localhost ~]# history 1 vi /etc/sysconfig/network-scripts/ifcfg-ens33 2 systemctl restart network.service 3 ip addr 4 ping -c 4 www.baidu.com 5 yum groupinstall -y "GNOME Desktop" 6 init5 7 init 5 8 vi /root/.ssh/authorized_keys 9 setenforce 0 10 vi /etc/selinux/config 11 mkdir /root/.ssh
[root@localhost ~]# echo $HISTSIZE 1000 //运行的命令只能保存1000条
[root@localhost ~]# history -c [root@localhost ~]# history 1 history
[root@localhost ~]# cat .bash_history vi /etc/sysconfig/network-scripts/ifcfg-ens33 systemctl restart network.service ip addr ping -c 4 www.baidu.com yum groupinstall -y "GNOME Desktop" init5 init 5 vi /root/.ssh/authorized_keys setenforce 0 vi /etc/selinux/config mkdir /root/.ssh chmod 700 /root/.ssh vi /root/.ssh/authorized_keys ssh -v yum install -y openssh-client yum install -y openssh-clients init 5 init 6
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
[root@localhost ~]# echo $HISTSIZE 1000 [root@localhost ~]# source /etc/profile [root@localhost ~]# echo $HISTSIZE 5000
[root@localhost ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S " [root@localhost ~]# echo $HISTTIMEFORMAT %Y/%m/%d %H:%M:%S [root@localhost ~]# history 1 2018/01/10 23:18:28 history 2 2018/01/10 23:20:12 cat bash_history 3 2018/01/10 23:20:38 cat .bash_history 4 2018/01/10 23:25:45 ls -l .bash_history 5 2018/01/10 23:25:49 ls 6 2018/01/10 23:26:44 vi /etc/profile 7 2018/01/10 23:32:44 echo $HISTSIZE 8 2018/01/10 23:33:02 source /etc/profile 9 2018/01/10 23:33:05 echo $HISTSIZE
新建一个ssh channel后就不在有用了,为了完全改变,须要对/etc/profile再次编辑
[root@localhost ~]# vim /etc/profile [root@localhost ~]# source !$ source /etc/profile
敲两下,系统会把全部的命令文件名列出来
[root@localhost ~]# yum install -y bash-completion
[root@localhost ~]# systemctl res rescue reset-failed restart [root@localhost ~]# systemctl restart network network-online.target network.service [root@localhost ~]# systemctl restart network.service
[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'
自定义的alias放到~/.bashrc
[root@localhost profile.d]# unalias restartnet [root@localhost profile.d]# restartnet bash: restartnet: 未找到命令...
[root@localhost ~]# echo "1111" > 1.txt [root@localhost ~]# cat 1.txt 1111
[root@localhost profile.d]# lsaa bash: lsaa: 未找到命令... [root@localhost profile.d]# lsaa 2>a.txt //将错误信息定向到a.txt中 [root@localhost profile.d]# cat a.txt bash: lsaa: 未找到命令...
[root@localhost ~]# echo "1111">>1.txt [root@localhost ~]# cat 1.txt 2221 1111 [root@localhost ~]# echo "1111">1.txt [root@localhost ~]# cat 1.txt 1111
[ ] ls aaa.txt 2>>err
[ ] wc -l < 1.txt
[root@localhost ~]# wc -l < 1.txt 1 //wc有多少文件?
[root@localhost ~]# >+2> == &>^C [root@localhost ~]# ls [12].txt aaa.txt &> a.txt [root@localhost ~]# cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt [root@localhost ~]# ls [12].txt aaa.txt &>> a.txt [root@localhost ~]# cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt