8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向
執(zhí)行過(guò)的命令Linux都會(huì)記錄,預(yù)設(shè)可以記錄1000條歷史命令。這些命令保存在用戶的家目錄的.bash_history文件中。只有當(dāng)用戶正常退出當(dāng)前shell時(shí),在當(dāng)前shell中運(yùn)行的命令才會(huì)保存至.bash_history文件中。
[root@lizhipeng01 ~]# history
1 ls -l .bash_history
2 vim /etc/profile
3 ls /root/.bash_history
4 cat /root/.bash_history
5 history
[root@lizhipeng01 ~]# echo $HISTSIZE? ? ? ?之前是1000,這個(gè)已經(jīng)被我改了
10000
[root@lizhipeng01 ~]# history -c? ?當(dāng)前命令歷史清空
[root@lizhipeng01 ~]# history
1 history
[root@lizhipeng01 ~]# cat .bash_history
[root@lizhipeng01 ~]# history -c
[root@lizhipeng01 ~]# ls -l .bash_history
-rw-------. 1 root root 26957 1月 8 06:40 .bash_history
[root@lizhipeng01 ~]# vim /etc/profile? ? ? ? ? ? 把它給成了5000
[root@lizhipeng01 ~]# echo $HISTSIZE? ? ? ?但是并沒有生效
10000
[root@lizhipeng01 ~]# source /etc/profile? ? ?source一下,生效了
[root@lizhipeng01 ~]# echo $HISTSIZE
5000
[root@lizhipeng01 ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
[root@lizhipeng01 ~]# echo $HISTTIMEFORMAT
%Y/%m/%d %H:%M:%S
打開另一個(gè)終端,沒有生效。僅在當(dāng)前終端生效。
[root@lizhipeng01 ~]# history
1 2018/01/09 07:39:08 ls -l .bash_history
2 2018/01/09 07:39:57 vim /etc/profile
3 2018/01/09 07:43:35 echo $HISTSIZE
4 2018/01/09 07:44:43 source /etc/profile
5 2018/01/09 07:44:49 echo $HISTSIZE
6 2018/01/09 07:48:01 HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
7 2018/01/09 07:49:22 echo $HISTTIMEFORMAT
8 2018/01/09 07:54:59 history
[root@lizhipeng01 ~]# vim /etc/profile
[root@lizhipeng01 ~]# source /etc/profile
[root@lizhipeng01 ~]# chattr +a ~/.bash_history只會(huì)追加,不會(huì)刪除,用戶用的命令,都會(huì)被記錄下來(lái)。
!!:連續(xù)兩個(gè)!表示執(zhí)行上一條指令。
!n:這里的n是數(shù)字,表示執(zhí)行命令歷史中的第n條指令。
!字符串:!pw表示執(zhí)行命令歷史中最近一次以pw開頭的命令。
[root@lizhipeng01 ~]# yum install -y bash-completion
[root@lizhipeng01 ~]# rpm -qa bash-completion
bash-completion-2.1-6.el7.noarch
[root@lizhipeng01 ~]# alias restartnet='systemctl restart network.service'
[root@lizhipeng01 ~]# restartnet
[root@lizhipeng01 ~]# vi .bashrc? 這個(gè)里面配置了幾個(gè)alias
[root@lizhipeng01 ~]# 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@lizhipeng01 ~]# cd /etc/profile.d/? ? ? ? ? ? ? ? ? ? ? ? ? alias定義在兩個(gè)地方,一個(gè)是?/etc/profile.d/? ,另一個(gè)是.bashrc
[root@lizhipeng01 profile.d]# ls
256term.csh bash_completion.sh colorgrep.sh colorls.sh lang.sh less.sh vim.sh which2.sh
256term.sh colorgrep.csh colorls.csh lang.csh less.csh vim.csh which2.csh
通配符
*來(lái)匹配零個(gè)或多個(gè)字符,用?匹配一個(gè)字符
[root@lizhipeng01 ~]# ls
111 234 a.txt dir3 test4 testc.txt 學(xué)習(xí)計(jì)劃安排.txt
123 2.txt.bak bb dir4 test5 Thinking_In_Java(中文版_第四版).pdf
1_hard.txt anaconda-ks.cfg dir2 split_dir testb.txt yum.log
[root@lizhipeng01 ~]# ls *.txt
1_hard.txt a.txt testb.txt testc.txt 學(xué)習(xí)計(jì)劃安排.txt
[root@lizhipeng01 ~]# ls ?.txt
a.txt
[root@lizhipeng01 ~]# ls [0-3].txt
ls: 無(wú)法訪問[0-3].txt: 沒有那個(gè)文件或目錄
[root@lizhipeng01 ~]# touch 1.txt 2.txt 3.txt
[root@lizhipeng01 ~]# ls [0-3].txt
1.txt 2.txt 3.txt
[root@lizhipeng01 ~]# ls [123].txt
1.txt 2.txt 3.txt
[root@lizhipeng01 ~]# ls {1,2}.txt
1.txt 2.txt
[root@lizhipeng01 ~]# ls {1,2,3}.txt
1.txt 2.txt 3.txt
輸入輸出重定向
[root@lizhipeng01 ~]# lsaaa 2> a.txt
[root@lizhipeng01 ~]# cat a.txt
-bash: lsaaa: 未找到命令
[root@lizhipeng01 ~]# lsaaa 2>> a.txt? ? ? 追加
[root@lizhipeng01 ~]# cat a.txt
-bash: lsaaa: 未找到命令
-bash: lsaaa: 未找到命令
[root@lizhipeng01 ~]# ls [12].txt aaa.txt &> a.txt? ? ? ?&> 把正確和錯(cuò)誤的信息輸出定向到a.txt
[root@lizhipeng01 ~]# cat a.txt
ls: 無(wú)法訪問aaa.txt: 沒有那個(gè)文件或目錄
1.txt
2.txt
[root@lizhipeng01 ~]# ls [12].txt aaa.txt &>> a.txt? ? ?追加
[root@lizhipeng01 ~]# cat a.txt
ls: 無(wú)法訪問aaa.txt: 沒有那個(gè)文件或目錄
1.txt
2.txt
ls: 無(wú)法訪問aaa.txt: 沒有那個(gè)文件或目錄
1.txt
2.txt
[root@lizhipeng01 ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt? ? ? ?正確的定向到1.txt,錯(cuò)誤的定向到a.txt
[root@lizhipeng01 ~]# cat 1.txt
1.txt
2.txt
[root@lizhipeng01 ~]# cat a.txt
ls: 無(wú)法訪問aaa.txt: 沒有那個(gè)文件或目錄
[root@lizhipeng01 ~]# wc -l < 1.txt
2
?
轉(zhuǎn)載于:https://www.cnblogs.com/sisul/p/8246452.html
總結(jié)
以上是生活随笔為你收集整理的8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: select 设置发送超时发送注意事项
- 下一篇: 表单文本两端对齐