案例1:命令列基礎技巧
案例2:掛載并訪問光碟設備
案例3:ls串列及檔案創建
案例4:復制、洗掉、移動
1 案例1:命令列基礎技巧
1.1 問題
本例要求掌握Linux命令列環境的基本操作,完成下列任務:
利用Tab鍵快速找出下列檔案:/etc/sysconfig/network-scripts/ifcfg-*、/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
練習以下快捷編輯操作:Ctrl + l、Ctrl + u、Ctrl + w;Ctrl + c、Esc + .
1.2 步驟
實作此案例需要按照如下步驟進行。
步驟一:利用Tab鍵快速補全檔案路徑
1)找出現有的網路連接組態檔
[root@server0 ~]# ls /etc/sysco<TAB>
[root@server0 ~]# ls /etc/sysconfig/netw<TAB>
[root@server0 ~]# ls /etc/sysconfig/network-s<TAB>
[root@server0 ~]# ls /etc/sysconfig/network-scripts/ifc<TAB>
[root@server0 ~]# ls /etc/sysconfig/network-scripts/ifcfg-<TAB><TAB>
ifcfg-br0 ifcfg-br1 ifcfg-lo
ifcfg-br0:253 ifcfg-eno16777736
2)找出RHEL7校驗軟體包的密鑰檔案
[root@server0 ~]# ls /etc/pki/rp<TAB>
[root@server0 ~]# ls /etc/pki/rpm-gpg/RP<TAB>
[root@server0 ~]# ls /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-r<TAB>
[root@server0 ~]# ls /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
步驟二:練習以下快捷編輯操作
1)清理編輯的命令列
快速清屏:Ctrl + l
從當前游標處洗掉到行首:Ctrl + u
從當前游標處往前洗掉一個單詞:Ctrl + w
2)放棄編輯的命令列
中止當前命令列:Ctrl + c
3)引數復用
在當前游標處粘貼上一條命令列的最后一個引數:Esc + .
2 案例2:掛載并訪問光碟設備
2.1 問題
本例要求學會mount掛載操作。主要完成下列任務:
連接光碟 /ISO/rhel-server-7.4-x86_64-dvd.iso
將光碟掛載到 /mnt 目錄,檢查 /mnt 目錄內容
卸載光碟設備,再次檢查目錄內容
2.2 步驟
實作此案例需要按照如下步驟進行。
步驟一:使用ls命令列出指定的檔案
1)連接光碟 /ISO/rhel-server-7.4-x86_64-dvd.iso
[root@server0 ~]# mount /dev/cdrom /mnt //掛載設備
mount: /dev/sr0 寫保護,將以只讀方式掛載
2)將光碟掛載到 /mnt 目錄,檢查 /mnt 目錄內容
[root@server0 ~]# ls /mnt //訪問設備內容
addons images Packages RPM-GPG-KEY-redhat-release
EFI isolinux release-notes TRANS.TBL
EULA LiveOS repodata
GPL media.repo RPM-GPG-KEY-redhat-beta
3)卸載光碟設備,再次檢查目錄內容
[root@server0 ~]# umount /mnt/dvd //卸載設備
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@server0 ~]# ls /mnt/dvd //確認結果
[root@server0 ~]#
3 案例3:ls串列及檔案創建
3.1 問題
本例要求學會串列查看目錄內容、新建檔案相關技能,并熟悉通配符機制的應用。主要完成下列任務:
使用ls命令列出指定的檔案:/etc/目錄下以re開頭.conf結尾的檔案、/dev/目錄下編號是個位數的tty控制臺設備
一條命令創建檔案夾 /protected/project/tts10
使用 vim 創建檔案 /etc/hostname,撰寫一行內容:svr7.tedu.cn
3.2 方案
對于通配符使用,需理解每個通配符的作用:
*:任意多個任意字符
?:單個字符
[a-z]:多個字符或連續范圍中的一個,若無則忽略
{a,min,xy}:多組不同的字串,全匹配
vim是Linux系統上最常用的命令列互動式文本編輯器,主要作業在三種模式:命令模式、輸入模式、末行模式。
通過vim打開一個檔案時,默認處于命令模式;從命令模式按i鍵可以進入編輯狀態,按Esc鍵回傳命令模式;從命令模式輸入冒號:可以進入末行模式,在末行模式下主要執行存盤、退出等基本操作。
3.3 步驟
實作此案例需要按照如下步驟進行。
步驟一:使用ls命令列出指定的檔案
1)列出/etc/目錄下以re開頭.conf結尾的檔案
使用通配符 * 代替未知的字串。
[root@server0 ~]# ls /etc/re*.conf
/etc/request-key.conf /etc/resolv.conf
2)列出/dev/目錄下編號是個位數的tty控制臺設備
使用通配符 ? 代替單個未知的字符。
[root@server0 ~]# ls /dev/tty?
/dev/tty0 /dev/tty2 /dev/tty4 /dev/tty6 /dev/tty8
/dev/tty1 /dev/tty3 /dev/tty5 /dev/tty7 /dev/tty9
或者更嚴謹一些,使用 [0-9] 代替單個數字。
[root@server0 ~]# ls /dev/tty[0-9]
/dev/tty0 /dev/tty2 /dev/tty4 /dev/tty6 /dev/tty8
/dev/tty1 /dev/tty3 /dev/tty5 /dev/tty7 /dev/tty9
步驟二:新建檔案
1)使用mkdir新建檔案夾
[root@server0 ~]# mkdir -p /protected/project/tts10
[root@server0 ~]# ls -ld /protected/project/tts10/
drwxr-xr-x. 2 root root 6 Aug 30 10:11 /protected/project/tts10/
2)使用vim新建或修改文本檔案
[root@server0 ~]# vim /etc/hostname
//按i鍵進入編輯模式
//將文本內容修改為 svr7.tedu.cn
//按Esc鍵回傳命令模式
//輸入:wq保存修改并退出vim編輯器
[root@server0 ~]# cat /etc/hostname
svr7.tedu.cn
4 案例4:復制、洗掉、移動
4.1 問題
本例要求學會對檔案進行復制、洗掉、移動/改名相關操作,依次完成下列任務:
在當前目錄下創建一個子目錄 dir1
將檔案夾 /boot/grub2/ 復制到目錄dir1下
將目錄 /root/ 下以 .cfg 結尾的檔案復制到dir1下
將檔案 /etc/redhat-release復制到 /root/ 下,同時改名為 version.txt
將檔案 /root/version.txt 移動到dir1目錄下
洗掉 dir1 目錄下的 grub2 子目錄
4.2 步驟
實作此案例需要按照如下步驟進行。
1)在當前目錄下創建一個子目錄 dir1
[root@server0 ~]# mkdir dir1
2)將檔案夾 /boot/grub2/ 復制到目錄dir1下
[root@server0 ~]# cp -r /boot/grub2/ dir1/
[root@server0 ~]# ls -ld dir1/* //檢查復制結果
drwxr-xr-x. 6 root root 104 Aug 30 10:27 dir1/grub2
3)將目錄 /root/ 下以 .cfg 結尾的檔案復制到dir1下
[root@server0 ~]# cp /root/*.cfg dir1/
[root@server0 ~]# ls -ld dir1/* //檢查復制結果
-rw-------. 1 root root 16793 Aug 30 10:29 dir1/anaconda-ks.cfg
drwxr-xr-x. 6 root root 104 Aug 30 10:27 dir1/grub2
4)將檔案 /etc/redhat-release復制到 /root/ 下,同時改名為 version.txt
[root@server0 ~]# cp /etc/redhat-release /root/version.txt
[root@server0 ~]# ls -ld /root/version.txt //檢查復制結果
-rw-r--r--. 1 root root 52 Aug 30 10:30 /root/version.txt
5)將檔案 /root/version.txt 移動到dir1目錄下
[root@server0 ~]# cp /root/version.txt dir1/
[root@server0 ~]# ls -ld dir1/* //檢查移動/改名結果
-rw-------. 1 root root 16793 Aug 30 10:29 dir1/anaconda-ks.cfg
drwxr-xr-x. 6 root root 104 Aug 30 10:27 dir1/grub2
-rw-r--r--. 1 root root 52 Aug 30 10:31 dir1/version.txt
6)洗掉 dir1 目錄下的grub2子目錄
[root@server0 ~]# rm -rf dir1/grub2/
[root@server0 ~]# ls -ld dir1/* //檢查洗掉結果
-rw-------. 1 root root 16793 Aug 30 10:29 dir1/anaconda-ks.cfg
-rw-r--r--. 1 root root 52 Aug 30 10:31 dir1/version.txt
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/61878.html
標籤:UNIX文化
