怎么理解shell,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
Shell是系統(tǒng)的用戶界面,提供了用戶與內(nèi)核進(jìn)行交互操作的一種接口。它接收用戶輸入的命令并把它送入內(nèi)核去執(zhí)行。
實(shí)際上Shell是一個(gè)命令解釋器,它解釋由用戶輸入的命令并且把它們送到內(nèi)核。不僅如此,Shell有自己的編程語(yǔ)言用
于對(duì)命令的編輯,它允許用戶編寫(xiě)由shell命令組成的程序。Shell編程語(yǔ)言具有普通編程語(yǔ)言的很多特點(diǎn),比如它也有
循環(huán)結(jié)構(gòu)和分支控制結(jié)構(gòu)等,用這種編程語(yǔ)言編寫(xiě)的Shell程序與其他應(yīng)用程序具有同樣的效果。
我們可以使用SHELL實(shí)現(xiàn)對(duì)Linux系統(tǒng)的大部分管理例如:
1. 文件管理
2. 用戶管理
3. 權(quán)限管理
4. 磁盤(pán)管理
5. 軟件管理
6. 網(wǎng)絡(luò)管理
......
使用Shell的兩種方式:
輸入命令 效率低 適合少量的工作
Shell Script 效率高 適合完成復(fù)雜,重復(fù)性工作
內(nèi)容提要:
bash shell提示符
shell 語(yǔ)法
bash 特性
Linux獲得幫助
一、bash shell提示符:
===================
[root@tianyun ~]# echo $PS1
[\u@\h \W]\$
[root@tianyun ~]# date
2019年 10月 24日 星期三 09:38:54 CST
[root@tianyun ~]# whoami
root
[root@tianyun ~]# useradd jack
[root@tianyun ~]# passwd jack
Changing password for user jack.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
二、shell 語(yǔ)法
=====================
命令 選項(xiàng) 參數(shù)
[root@tianyun ~]# ls
[root@tianyun ~]# ls -a
[root@tianyun ~]# ls -a /home
命令:整條shell命令的主體
選項(xiàng):會(huì)影響會(huì)微調(diào)命令的行為 //通常以 -, --
參數(shù):命令作用的對(duì)象
三、bash基本特性
1. 自動(dòng)補(bǔ)全<tab>
# ls /etc/sysconfig/network-scripts/
# ls /etc/sysconfig/network-scripts/ifcfg-eth0
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# systemctl restart crond.service
# date -s 12:30
2. 快捷鍵
^C 終止前臺(tái)運(yùn)行的程序 //ping 10.18.40.100
^D 退出 等價(jià)exit
^L 清屏
^A 光標(biāo)移到命令行的最前端 //編輯命令
^E 光標(biāo)移到命令行的后端 //編輯命令
^U 刪除光標(biāo)前所有字符 //編輯命令
^K 刪除光標(biāo)后所有字符 //編輯命令
^R 搜索歷史命令,利用關(guān)鍵詞
Alt+. 引用上一個(gè)命令的最后一個(gè)參數(shù),等價(jià)于!$
ESC . 引用上一個(gè)命令的最后一個(gè)參數(shù),等價(jià)于!$
# ls /etc/sysconfig/network-scripts/ifcfg-eth0
# cat ESC .
3. 歷史命令
# history
a. 光標(biāo)上下鍵
b. ^R //搜索歷史命令(輸入一段某條命令的關(guān)鍵字:必須是連續(xù)的)
c. !220 //執(zhí)行歷史命令中第220條命令
!字符串 //搜索歷史命令中最近一個(gè)以xxxx字符開(kāi)頭的命令,例如!ser
!$ //引用上一個(gè)命令的最后一個(gè)參數(shù)
示例1:
[root@instructor ~]# ls /root /home
[root@instructor ~]# cd !$
cd /home
示例2:
[root@instructor ~]# ls /root /home
[root@instructor ~]# touch !$/file1
touch /home/file1
示例3:
[root@instructor ~]# systemctl restart crond
[root@instructor ~]# ls
[root@instructor ~]# date
[root@instructor ~]# !sy
一周之后講
4. 命令別名
[root@tianyun ~]# alias tianyun='cat /etc/sysconfig/network-scripts/ifcfg-eth0' //建立別名(臨時(shí)的,僅在當(dāng)前Shell生效)
[root@tianyun ~]# unalias tianyun //取消tianyun這個(gè)別名
[root@tianyun ~]# alias //查看系統(tǒng)當(dāng)前的別名
ll='ls -l --color=tty'
[root@tianyun ~]# ll
[root@tianyun ~]# /bin/ls
[root@tianyun ~]# /bin/ls --color
[root@tianyun ~]# type -a ls //查看命令類型
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
[root@tianyun ~]# /bin/ls
[root@tianyun ~]# /usr/bin/ls
[root@tianyun ~]# ls //別名優(yōu)先
[root@tianyun ~]# \ls //跳過(guò)別名
[root@tianyun ~]# cp -rf /etc /tmp //第一次
[root@tianyun ~]# cp -rf /etc /tmp //第二次
[root@tianyun ~]# \cp -rf /etc /tmp
[root@tianyun ~]# type -a cp
cp is aliased to ‘cp -i’
cp is /usr/bin/cp
cp is /bin/cp
永久別名:
/etc/bashrc shell配置文件之一
[root@tianyun ~]# gedit /etc/bashrc //添加如下行
alias tianyun='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
四、Linux獲得幫助
1. 命令 --help
# ls --help
用法:ls [選項(xiàng)]... [文件]...
ls 常見(jiàn)選項(xiàng)
-a all,查看目錄下的所有文件,包括隱藏文件
-l 長(zhǎng)列表顯示
-h human 以人性化方式顯示出來(lái)
-d 只列出目錄名,不列出其他內(nèi)容
-t 按修改時(shí)間排序
-S 按文件的Size排序
-r 逆序排列reverse
-i 顯示文件的inode號(hào)(索引號(hào))
# date --help
Usage: date [OPTION]... [+FORMAT]
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
# date
# date +%H
# date +%F
# date 0214080019
# date 0214080019.30
# date -s 12:00
[root@tianyun ~]# touch `date +%F`_file.txt
[root@tianyun ~]# ls
2017-07-24_file.txt
兩種時(shí)間:
硬件時(shí)間,即主板BIOS時(shí)間
系統(tǒng)時(shí)間,即Linux系統(tǒng)時(shí)間
2. man 手冊(cè)名 (針對(duì)命令幫助,針對(duì)配置文件幫助,針對(duì)函數(shù)幫助)
[root@tianyun ~]# man man
MANUAL SECTIONS
The standard sections of the manual include:
1 User Commands
2 System Calls
3 C Library Functions
4 Devices and Special Files
5 File Formats and Conventions
6 Games et. Al.
7 Miscellanea
8 System Administration tools and Deamons
命令幫助: 章節(jié)1,章節(jié)8
函數(shù)幫助: 章節(jié)2,章節(jié)3
文件格式: 章節(jié)5
一般情況是不需要使用章節(jié)號(hào),例如:
# man ls
# man useradd
# man setfacl (/EXAMPLES)
技巧1:按章節(jié)查詢
/usr/bin/passwd 修改用戶口令命令
/etc/passwd 包含用戶信息的配置文件
# man -f passwd 列出所有章節(jié)中的passwd手冊(cè)
# man 1 passwd passwd命令的幫助
# man 5 passwd 用戶配置文件的幫助
技巧2:在所有章節(jié)中查詢
# man -a passwd
關(guān)于怎么理解shell問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
當(dāng)前題目:怎么理解shell-創(chuàng)新互聯(lián)
標(biāo)題網(wǎng)址:http://www.hntjjpw.com/article4/ddieoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、做網(wǎng)站、定制開(kāi)發(fā)、網(wǎng)站收錄、面包屑導(dǎo)航、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容