練習(xí)?: 復(fù)習(xí)
1. 打開終端窗?, 使? pwd 命令查看??所在?錄.
pwd
2. 使? cd 命令通過相對路徑切換到根(/)?錄
cd ../..
3. 使? cd - 切換到上次所在的?錄
cd -
4. 使? ls 命令以列表的形式查看當(dāng)前?錄下所有的?件(包括隱藏?件),并將輸出結(jié)果重定向到桌?的 my.txt ?件中.
ls -la > Desktop/my.txt
5. 在當(dāng)前?錄中使? cat 命令查看?件內(nèi)容.
cat Desktop/my.txt
6. 使? cd 命令通過絕對路徑?式切換到桌??錄下
cd /home/zhen/Desktop
7. 使? mkdir -p 命令在桌??錄創(chuàng)建 hello1 ?錄、hello2 ?錄, 并在hello1?錄創(chuàng)建??錄 world1, 在 hello2 ?錄下創(chuàng)建??錄 world2.
mkdir -p hello1/world1 hello2/world2
8. 在桌?創(chuàng)建 a.txt、b.txt、c.log、d.log 四個(gè)?件.
touch a.txt b.txt c.log d.log
①. 雙擊打開 a.txt, 并在?件中輸?內(nèi)容 hello a.txt
②. 雙擊打開 b.txt, 并在?件中輸?內(nèi)容 hello.b.txt
③. 雙擊打開 c.log, 并在?件中輸?內(nèi)容 hello c.log
④. 雙擊打開 d.log, 并在?件中輸?內(nèi)容 hello d.log
9. 使? ls *.log 查看所有的以 log 結(jié)尾的?件, 并將所有以 log 結(jié)尾的?件名寫?到 桌?的 file.log ?件中
ls *.log > file.log
10. 使? cat 命令將 a.txt b.txt ?件內(nèi)容合并到 ab.txt ?件, 并將 ab.txt?件移動(dòng)到 hello1/world1 ?錄中.
cat a.txt b.txt > ab.txt
mv ab.txt hello1/world1
11. 使? cat 命令將 c.log d.log ?件內(nèi)容合并到 cd.log ?件, 并將 cd.log?件移動(dòng)到 hello2/world2 ?錄中.
cat c.log d.log > cd.log
mv cd.log hello2/world2/cd.log
12. 使? tree 命令查看桌??錄結(jié)構(gòu), 并將輸出結(jié)果存儲(chǔ)到桌?的abcd.txt ?件中.
tree > abcd.txt
13. 使? cat 命令查看 abcd.txt ?件內(nèi)容
cat abcd.txt
14. 使? mkdir 命令創(chuàng)建 backup ?錄, 將 hello1、hello2 兩個(gè)?錄拷?到 backup ?錄中.
mkdir backup
cp -r hello1 hello2 backup
15. 使? ls --help 命令將 ls 幫助信息保存到桌??錄下 help.txt ?件中
ls --help > help.txt
16. 使? rm 命令刪除 abcd.txt ?件
rm abcd.txt
17. 使? rm 命令刪除 hello1、hello2 兩個(gè)?錄
rm -r hello1 hello2
18. 使? mv 命令將 help.txt ?件重命名為 ls_help.txt, 并移動(dòng)到 backup?錄中.
mv help.txt ls_help.txt
19. 使? rm *.txt *.log 刪除桌?以 log 結(jié)尾、以 txt 結(jié)尾的所有?件.(注意: 如果桌?有其他重要?件,?定要備份好).
rm *.txt *.log
20. 最后桌?就剩下 backup ?錄.
練習(xí)?: grep
1. 在 test.txt 中使? grep 命令查找 包含數(shù)字 12 的所有?.
grep 12 test.txt
2. 在 test.txt 中使? grep 命令查找包含 will 的所有?.
grep 'will' test.txt
3. 在 test.txt 中使? grep 命令查找以 t 或者 a 開頭的所有?
grep '^[ta]' test.txt
4. 在 test.txt 中使? grep 命令查找以 years 結(jié)尾的所有?
grep 'years$' test.txt
5. 在 test.txt 中使? grep ‘^…e’ test.txt 命令查找滿?條件的所有?
grep '^..e' test.txt
練習(xí)三: 管道
1. 使? cd 命令切換到 /usr/bin ?錄下
cd /usr/bin
2. 使?管道 ls | grep ‘^n’ 將以 n 開頭的?件名寫?到桌?的 files.txt ?件中
ls | grep '^n' > /home/zhen/Desktop/file.txt
3. 使?管道以列表的形式將所有的?m結(jié)尾的?件名字追加寫?到桌?的 file.txt ?件中
ls | grep -v 'm$' >> /home/zhen/Desktop/file.txt
練習(xí)四: ln
1. 使? echo ‘hello world’ > hello.txt 命令在桌?創(chuàng)建 hello.txt ?件.
echo 'hello world' > hello.txt
2. 使? mkdir 在桌?創(chuàng)建 folder ?錄
mkdir folder
3. 使? ln -s 命令在桌?創(chuàng)建 hello.txt ?件的軟鏈接 symbolic_link
ln -s hello.txt symbolic_link
4. 使? cat symbolic_link 命令通過軟鏈接查看 hello.txt ?本內(nèi)容
cat symbolic_link
5. 使? mv 命令將 symbolic_link 移動(dòng)到 folder ?錄下
mv symbolic_link folder/
6. 使? cd 命令切換到 folder ?錄下
cd folder
7. 使? cat symbolic_link 命令通過軟鏈接再次查看 hello.txt ?本內(nèi)容,是否能查看? 提示信息是什么?
不能查看,報(bào)錯(cuò):cat: symbolic_link: No such file or directory
8. 使? rm 命令刪除軟連接 symbolic_link
rm symbolic_link
9. 使? cd 命令回到桌?
cd ..
10. 使? ln -s 命令通過絕對路徑?式創(chuàng)建對 hello.txt ?件的軟連接symbolic_link
ln -s /home/zhen/Desktop/hello.txt symbolic_link
11. 使? mv 命令將 symbolic_link 移動(dòng)到folder?錄下
mv symbolic_link folder
12. 使? cat symbolic_link 命令通過軟鏈接再次查看 hello.txt ?本內(nèi)容,是否能查看?
cd floder
cat symbolic_link
13. 使? cd 命令切換到桌?
cd ..
14. 使? rm 刪除源?件 hello.txt
rm hello.txt
15. 使? cd 切換到folder ?錄, 使? cat 命令通過軟連接 symbolic_link查看?件內(nèi)容, 是否能夠查看?
不能,報(bào)錯(cuò):
cat: symoblic_link: No such file or directory
16. 使? cd 命令切換到桌?
cd ..
17. 使? echo ‘hello world’ > hello.txt 命令在桌?創(chuàng)建 hello.txt ?件.
echo 'hello world' > hello.txt
18. 使? ln 命令創(chuàng)建對 hello.txt ?件的硬鏈接 hard_link
ln hello.txt hard_link
19. 使? rm 命令刪除源?件 hello.txt
rm hello.txt
20. 使? cat hard_link 命令查看?件內(nèi)容, 是否能夠查看?
cat hard_link
可以查看,硬鏈接相當(dāng)于備份
練習(xí)五: chmod
1. 使? cd 命令進(jìn)?桌??錄
cd /home/zhen/Desktop
2. 使? touch 命令創(chuàng)建 hello1.txt、hello2.txt ?件
touch hello1.txt hello2.txt
3. 使? chmod 字?法給 hello1.txt ?件設(shè)置權(quán)限: ?戶 rw ?戶組: r 其他: x
chmod u=rw,g=r,o=x hello1.txt
4. 使? chmod 字?法給 hello2.txt ?件設(shè)置權(quán)限: ?戶r ?戶組: x 其他:rw
chmod u=r,g=x,o=rw hello2.txt
5. 雙擊打開 hello2.txt, 是否能夠編輯該?件?
可以打開,編輯的內(nèi)容不能保存
6. 在桌?創(chuàng)建?錄 folder
mkdir folder
7. 在 folder ?錄中創(chuàng)建 a.txt b.txt ?件
touch folder/a.txt folder/b.txt
8. 使? chmod 命令去掉 folder?錄的?戶的 r 權(quán)限
chmod u-r folder
9. 使? ls folder 命令嘗試查看?件列表, 注意是否能夠查看?
ls folder
不能,報(bào):ls: cannot open directory 'folder/': Permission denied
10. 使? chmod 命令給 folder?錄?戶增加 r權(quán)限
chmod u+r folder
11. 使? ls folder 命令能夠查看?件列表
ls folder
12. 使? chmod 命令去掉 folder ?錄?戶的 w 權(quán)限
chmod u-w folder
13. 使? cd 命令切換到 folder ?錄中, 嘗試使? touch 命令創(chuàng)建?件test.txt
cd folder
touch test.txt
不可以,創(chuàng)建報(bào)錯(cuò):touch: cannot touch 'test.txt': Permission denied
14. 使? cd 回到 folder ?錄的上?級?錄
cd ..
15. 使? chmod 命令為 folder ?錄增加 w 權(quán)限
chmod u+w folder
16. 再次嘗試在 folder ?錄中創(chuàng)建 test.txt ?件
touch folder/test.txt
可以創(chuàng)建
練習(xí)六:vim
1. 使? cd 命令切換到桌??錄
cd /home/zhen/Desktop
2. 使? vim 創(chuàng)建 hello.txt ?件
vim hello.txt
3. 輸? i 切換到編輯模式
i
4. 在 hello.txt ?件中輸?以下內(nèi)容
《詠泰?》
遠(yuǎn)看泰??乎乎,
上頭細(xì)來下頭粗.
如把泰?倒過來,
下頭細(xì)來上頭粗.
5. 使? ESC 鍵切換到命令模式
ESC
6. 輸?冒號(hào)(:w) 完成?件內(nèi)容保存.
:w
7. 再次輸?冒號(hào)(:set nu) 顯示?件?號(hào).
:set nu
8. 再次輸?冒號(hào)(:3) 光標(biāo)移動(dòng)到第3?
:3
9. 在命令模式下, 輸?O在第3?上?增加??, 內(nèi)容以下:
以上兩句詩歌充分表達(dá)了詩人對泰山的曖昧.文章來源:http://www.zghlxwxcb.cn/news/detail-512054.html
O
以上兩句詩歌充分表達(dá)了詩人對泰山的曖昧.
10. 在命令模式下, 輸? G 光標(biāo)定位到?件末尾
Esc
G
11. 在命令模式下, 輸? o 在末尾?后?增加?樣, 內(nèi)容如下:
以上兩句詩歌充分表達(dá)了詩人亂七八糟的心態(tài).文章來源地址http://www.zghlxwxcb.cn/news/detail-512054.html
O
以上兩句詩歌充分表達(dá)了詩人亂七八糟的心態(tài).
- 在命令模式下, 輸? v 選中詩歌的前 4 ?
Esc
v
13. 在命令模式下, 將前4?中的泰?兩個(gè)字替換成??.
:1,4s/泰山/黃山/g
14. 在命令模式下, 拷?最后兩?內(nèi)容
2yy
15. 在命令模式下, 將拷?的內(nèi)容粘貼到第3?下?.
:4
p
16. 在命令模式下, 使? dd 刪除第3?內(nèi)容.
:3
dd
17. 在命令模式下, 退出保存該?件.
:wq
到了這里,關(guān)于Linux shell練習(xí)題——grep、|、ln、chmod、vim的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!