[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