5.修改文件內(nèi)容 vi
- 創(chuàng)建/修改/oldboy/oldboy.txt
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="python" cid="n130" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> [root@first ~]# vi /oldboy/oldboy.txt
[root@first ~]# ls -l /oldboy
total 4
-rw-r--r--. 1 root root 15 Jan 2 19:16 oldboy.txt
[root@first ~]#
?
第1個(gè)里程碑-vi 文件名名稱
vi /oldboy/oldboy.txt
?
第2個(gè)里程碑-vi 文件編輯模式
按i(小寫字母I)#INSERT 插入 編輯模式
?
第3個(gè)里程碑-退出編輯模式
按esc 退出編輯模式
?
第4個(gè)里程碑-保存并退出
:wq #保存并退出 write quit #:英文狀態(tài)下
:q! #強(qiáng)制退出不保存
?
:wq蠢棱! #強(qiáng)制保存退出 ZZ
:q #只退出不保存</pre>
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="python" cid="n131" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> [root@first ~]# ls -l /oldboy/oldboy.txt
-rw-r--r--. 1 root root 15 Jan 2 19:16 /oldboy/oldboy.txt
查看文件內(nèi)容
[root@first ~]# cat /oldboy/oldboy.txt
we are family.
[root@first ~]#
?
?
路徑:/ /oldboy
/oldboy/oldboy.txt(無空格)
?
擴(kuò)展:
[root@oldboyedu ~]# [ -f /oldboy/oldboy.txt ] && echo 1 ||
echo 0
0</pre>
6.查看文件內(nèi)容 cat
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" cid="n133" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> #查看文件內(nèi)容
[root@first ~]# cat /oldboy/oldboy.txt
we are family.
[root@first ~]# </pre>
7.絕對(duì)路徑和相對(duì)路徑
絕對(duì)路徑:從根開始的路徑
8.刪除文件或目錄 rm remove
-f force 強(qiáng)制刪除不提示
-r 遞歸刪除 一層一層刪除目錄及目錄內(nèi)容
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="python" cid="n139" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> [root@first ~]# rm -fr /oldboy/
[root@first ~]# ls -l /oldboy
ls: cannot access /oldboy: No such file or directory
[root@first ~]# </pre>
實(shí)際工作環(huán)境中慎用惶凝,通常mv 替換
使用的時(shí)候 危險(xiǎn)的參數(shù) 可以放在最后
<pre spellcheck="false" class="md-fences mock-cm md-end-block md-fences-with-lineno" lang="python" cid="n142" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 8px; margin-bottom: 15px; margin-top: 15px; width: inherit;">rm /oldboy/ -fr
</pre>
9.移動(dòng)文件或目錄 mv
- 移動(dòng)
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="http" cid="n147" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> #把 /oldboy 目錄移動(dòng)到 /tmp 下面
[root@first ~]# mkdir /oldboy
[root@first ~]# mv /oldboy/ /tmp/
[root@first ~]# ls -l /oldboy/ /tmp/
ls: cannot access /oldboy/: No such file or directory
/tmp/:
total 8
-rw-r--r--. 1 root root 359 Jan 2 17:24 ifcfg-ens33
-rwx------. 1 root root 836 Dec 27 11:39 ks-script-2VtDda
-rw-r--r--. 1 root root 0 Jan 2 16:43 lidao
-rw-------. 1 root root 0 Dec 27 11:32 lidao.log
drwxr-xr-x. 2 root root 6 Jan 2 19:44 oldboy
drwx------. 2 root root 6 Dec 27 11:45 vmware-root_6490-700681864
drwxr-xr-x. 2 root root 6 Jan 2 16:57 yumlog
[root@first ~]# </pre>
- 修改文件/目錄名字
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="python" cid="n151" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> #把/tmp/lidao 修改為 /tmp/oldboy
[root@first tmp]# ls -l /tmp/
total 8
-rw-r--r--. 1 root root 359 Jan 2 17:24 ifcfg-ens33
-rwx------. 1 root root 836 Dec 27 11:39 ks-script-2VtDda
drwxr-xr-x. 3 root root 20 Jan 2 20:08 lidao
-rw-------. 1 root root 0 Dec 27 11:32 lidao.log
drwx------. 2 root root 6 Dec 27 11:45 vmware-root_6490-700681864
drwxr-xr-x. 2 root root 6 Jan 2 16:57 yumlog
[root@first tmp]# mv /tmp/lidao/ /tmp/oldboy
[root@first tmp]# ls -l /tmp/
total 8
-rw-r--r--. 1 root root 359 Jan 2 17:24 ifcfg-ens33
-rwx------. 1 root root 836 Dec 27 11:39 ks-script-2VtDda
-rw-------. 1 root root 0 Dec 27 11:32 lidao.log
drwxr-xr-x. 3 root root 20 Jan 2 20:08 oldboy
drwx------. 2 root root 6 Dec 27 11:45 vmware-root_6490-700681864
drwxr-xr-x. 2 root root 6 Jan 2 16:57 yumlog
[root@first tmp]#
把/tmp/oldboy 移動(dòng)到 /tmp/oldboy目錄中 并修改名字為yum.log
[root@first ~]# mkdir /tmp/oldboy
[root@first ~]# mkdir /tmp/lidao
[root@first ~]# mv /tmp/oldboy/ /tmp/lidao
[root@first ~]# ls /tmp/lidao
oldboy
?
[root@first ~]# mv /tmp/lidao/oldboy/ /tmp/lidao/yum.log
[root@first ~]# ls -l /tmp/lidao
total 0
drwxr-xr-x. 2 root root 6 Jan 2 20:35 yum.log
[root@first ~]# </pre>
10.查詢命令幫助
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" cid="n153" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> [root@first ~]#man ls(命令)
NAME 命令簡單說明
SYNOPSIS 命令的格式 []在這個(gè)格式在[]可以省略
-字母 命令參數(shù)
()小括號(hào) []中括號(hào) {}大括號(hào)</pre>
11.復(fù)制文件或目錄 cp copy
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="python" cid="n155" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> #復(fù)制
把/etc/sysconfig/network-scripts/ifcfgens33或 ifcfg-eth0 復(fù)制到 /tmp下面
[root@first ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /temp/
[root@first ~]#[root@first ~]# ls -l /temp/ifcfg-ens33
-rw-r--r--. 1 root root 359 Jan 2 20:55 /temp/ifcfg-ens33
備份
操作前備份 操作后檢查
[root@oldboyedu ~]# #給/etc/hosts 文件備份下
[root@oldboyedu ~]# cp /etc/hosts /etc/hosts.bak
[root@oldboyedu ~]# #bak backup 備份</pre>
12.顯示內(nèi)容到屏幕echo
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="python" cid="n157" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> #顯示內(nèi)容到屏幕 echo
[root@css ~]# echo oldboy
oldboy
[root@css ~]# echo oldboy lidao alex
oldboy lidao alex
[root@css ~]# mkdir /oldboy
[root@css ~]#
[root@css ~]# echo oldboy >/oldboy/lidao.txt
> 重定向符號(hào) 把信息寫入到文件中
[root@css ~]# cat /oldboy/lidao.txt
oldboy
[root@css ~]#
> 重定向符號(hào) 先清空文件再把信息寫入到文件中
[root@css ~]# echo alex lidao >/oldboy/lidao.txt
[root@css ~]# cat /oldboy/lidao.txt
css
[root@css ~]#
>> 追加輸出重定向符號(hào) 把信息寫入到文件結(jié)尾
[root@css ~]# echo csm >> /oldboy/lidao.txt
[root@css ~]# echo csm >> /oldboy/lidao.txt
[root@css ~]# echo csm >> /oldboy/lidao.txt
[root@css ~]# echo csm >> /oldboy/lidao.txt
[root@css ~]# cat /oldboy/lidao.txt
css
csm
csm
csm
csm
[root@css ~]# </pre>
13.打包壓縮(備份)tar
<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm" lang="python" cid="n159" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit;"> #創(chuàng)建壓縮包
tar zcvf 位置/壓縮包名稱 你要壓縮的文件或目錄
z 通過gzip工具壓縮
c create 創(chuàng)建
v verbose 顯示過程
f file 指定壓縮包及位置
?
[root@css ~]# tar zcf /csm/etc.tar.gz etc/
[root@css ~]# ls -l /csm/
總用量 11036
drwxr-xr-x. 3 root root 17 12月 31 19:14 csm
-rw-r--r--. 1 root root 11298465 1月 3 19:21 etc.tar.gz
[root@css ~]#
?
?
解壓
tar zxf
[root@css ~]# ls -l /csm
總用量 11040
drwxr-xr-x. 3 root root 17 12月 31 19:14 csm
-rw-r--r--. 1 root root 138 1月 3 19:26 css.tar.gz
-rw-r--r--. 1 root root 11298465 1月 3 19:21 etc.tar.gz
[root@css ~]# tar zxf /csm/etc.tar.gz
[root@css ~]# ls -l
總用量 24
-rw-------. 1 root root 1337 12月 29 17:21 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 1月 2 10:54 catalina.out
drwxr-xr-x. 2 root root 6 1月 3 16:15 ccc
drwxr-xr-x. 2 root root 6 1月 2 10:06 csm
-rw-r--r--. 1 root root 28 12月 31 19:28 css
-rw-r--r--. 1 root root 0 1月 2 12:01 css.php
-rw-r--r--. 1 root root 0 1月 2 10:28 css.txt
-rw-r--r--. 1 root root 0 1月 2 11:34 css.txt~
-rw-r--r--. 1 root root 0 1月 2 12:46 css.txw~
-rw-r--r--. 1 root root 0 1月 2 12:45 css.txx~
-rw-r--r--. 1 root root 0 1月 2 12:42 css.txy~
-rw-r--r--. 1 root root 0 1月 2 12:39 css.txz~
-rw-r--r--. 1 root root 0 1月 2 09:30 c.txt
drwxr-xr-x. 79 root root 8192 1月 3 14:28 etc
-rw-r--r--. 1 root root 82 12月 31 19:31 ljs
-rw-r--r--. 1 root root 0 1月 2 11:52 ljs.txt
drwxr-xr-x. 2 root root 6 1月 3 14:31 oldboy
-rw-r--r--. 1 root root 0 1月 2 09:30 rename
-rw-r--r--. 1 root root 0 1月 2 10:03 text.txt
[root@css ~]# pwd
/root
[root@css ~]# ls -l /csm
總用量 11040
drwxr-xr-x. 3 root root 17 12月 31 19:14 csm
-rw-r--r--. 1 root root 138 1月 3 19:26 css.tar.gz
-rw-r--r--. 1 root root 11298465 1月 3 19:21 etc.tar.gz
[root@css ~]# tar zxf /csm/etc.tar.gz
[root@css ~]# ls -l
總用量 24
-rw-------. 1 root root 1337 12月 29 17:21 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 1月 2 10:54 catalina.out
drwxr-xr-x. 2 root root 6 1月 3 16:15 ccc
drwxr-xr-x. 2 root root 6 1月 2 10:06 csm
-rw-r--r--. 1 root root 28 12月 31 19:28 css
-rw-r--r--. 1 root root 0 1月 2 12:01 css.php
-rw-r--r--. 1 root root 0 1月 2 10:28 css.txt
-rw-r--r--. 1 root root 0 1月 2 11:34 css.txt~
-rw-r--r--. 1 root root 0 1月 2 12:46 css.txw~
-rw-r--r--. 1 root root 0 1月 2 12:45 css.txx~
-rw-r--r--. 1 root root 0 1月 2 12:42 css.txy~
-rw-r--r--. 1 root root 0 1月 2 12:39 css.txz~
-rw-r--r--. 1 root root 0 1月 2 09:30 c.txt
drwxr-xr-x. 79 root root 8192 1月 3 14:28 etc
-rw-r--r--. 1 root root 82 12月 31 19:31 ljs
-rw-r--r--. 1 root root 0 1月 2 11:52 ljs.txt
drwxr-xr-x. 2 root root 6 1月 3 14:31 oldboy
-rw-r--r--. 1 root root 0 1月 2 09:30 rename
-rw-r--r--. 1 root root 0 1月 2 10:03 text.txt
[root@css ~]# #默認(rèn)解壓到當(dāng)前路徑
[root@css ~]# pwd
/root</pre>