日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向

發布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

執行過的命令Linux都會記錄,預設可以記錄1000條歷史命令。這些命令保存在用戶的家目錄的.bash_history文件中。只有當用戶正常退出當前shell時,在當前shell中運行的命令才會保存至.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,這個已經被我改了
10000

[root@lizhipeng01 ~]# history -c? ?當前命令歷史清空

[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

打開另一個終端,沒有生效。僅在當前終端生效。

[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只會追加,不會刪除,用戶用的命令,都會被記錄下來。

!!:連續兩個!表示執行上一條指令。

!n:這里的n是數字,表示執行命令歷史中的第n條指令。

!字符串:!pw表示執行命令歷史中最近一次以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? 這個里面配置了幾個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定義在兩個地方,一個是?/etc/profile.d/? ,另一個是.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

通配符

*來匹配零個或多個字符,用?匹配一個字符

[root@lizhipeng01 ~]# ls
111 234 a.txt dir3 test4 testc.txt 學習計劃安排.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 學習計劃安排.txt

[root@lizhipeng01 ~]# ls ?.txt
a.txt

[root@lizhipeng01 ~]# ls [0-3].txt
ls: 無法訪問[0-3].txt: 沒有那個文件或目錄
[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? ? ? ?&> 把正確和錯誤的信息輸出定向到a.txt
[root@lizhipeng01 ~]# cat a.txt
ls: 無法訪問aaa.txt: 沒有那個文件或目錄
1.txt
2.txt

[root@lizhipeng01 ~]# ls [12].txt aaa.txt &>> a.txt? ? ?追加
[root@lizhipeng01 ~]# cat a.txt
ls: 無法訪問aaa.txt: 沒有那個文件或目錄
1.txt
2.txt
ls: 無法訪問aaa.txt: 沒有那個文件或目錄
1.txt
2.txt

[root@lizhipeng01 ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt? ? ? ?正確的定向到1.txt,錯誤的定向到a.txt
[root@lizhipeng01 ~]# cat 1.txt
1.txt
2.txt
[root@lizhipeng01 ~]# cat a.txt
ls: 無法訪問aaa.txt: 沒有那個文件或目錄

[root@lizhipeng01 ~]# wc -l < 1.txt
2

?

轉載于:https://www.cnblogs.com/sisul/p/8246452.html

總結

以上是生活随笔為你收集整理的8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。