1. 程式人生 > >2018-03-07阿銘Linux學習

2018-03-07阿銘Linux學習

Linux學習

8.1 shell介紹

shell 是一個命令解釋器,提供用戶和機器之間的交互
支持特定語法,比如邏輯判斷、循環
每個用戶都可以有自己特定的shell
CentOS7默認shell為bash(Bourne Agin Shell)

還有zsh、ksh等

8.2 命令歷史

history
.bash_history
默認1000條
變量HISTSIZE
/etc/profile 中修改
HISTTIMEFORMAT="%Y%m%d %H:%M:%S "   指定歷史記錄的格式
永久保存 chattr +a ~/.bash_history
!!       //上次執行的命令
!n       //執行第幾條命令
!word    //word 最近執行命令的前幾個字符

    [root@aming-01 ~]# echo $HISTSIZE
    1000
    [root@aming-01 ~]# vim /etc/profile    //更改HISTSIZE=2000
    [root@aming-01 ~]# echo $HISTSIZE
    1000
    [root@aming-01 ~]# source /etc/profile
    [root@aming-01 ~]# echo $HISTSIZE
    2000

history -c  清空內存中的命令記錄

    [root@aming-01 ~]# vim /etc/profile
            HISTSIZE=2000
            HISTTIMEFORMAT="%Y%m%d %H:%M:%S "   //添加的
    [root@aming-01 ~]# source /etc/profile
    [root@aming-01 ~]# history

8.3 命令補全和別名

    [root@aming-01 d6z]# rpm -q bash-completion
    bash-completion-2.1-6.el7.noarch
    [root@aming-01 d6z]# yum install -y bash-completion
    安裝完成後需要重啟才能支持

tab鍵,敲一下,敲兩下
參數補全,安裝 bash-completion
alias 別名給命令重新起個名字
各用戶都有自己配置別名的文件 ~/.bashrc
ls /etc/profile.d/
自定義的 alias 放到 ~/.bashrc

8.4 通配符

ls *.txt
ls ?.txt
ls [0-9].txt
ls {1,2}.txt
cat 1.txt > 2.txt
cat 1.txt >> 2.txt
ls aaa.txt 2> err
ls aaa.txt 2>> err
wc -l < 1.txt
command > 1.txt 2> &1

*    任意字符
?   一個任意字符
[]   方括號中的字符任選一個
{}   花括號中的字符任選一個

8.5 輸入輸出重定向

>   輸出
>>  追加
2>  錯誤輸出
2>> 錯誤輸出追加
<   輸入

    [root@aming-01 ~]# ls > 1.txt
    [root@aming-01 ~]# w >> 1.txt
    [root@aming-01 ~]# lsaa 2>> 1.txt
    [root@aming-01 ~]# cat 1.txt
    1.txt
    anaconda-ks.cfg
     23:08:03 up  1:04,  1 user,  load average: 0.00, 0.01, 0.05
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.104.1    22:04    3.00s  0.18s  0.01s w
    -bash: lsaa: 未找到命令

    [root@aming-01 ~]# wc -l < 1.txt
    6

2018-03-07阿銘Linux學習