5.修改文件内容 vi
- 创建/修改/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个里程碑-vi 文件名名称
vi /oldboy/oldboy.txt
第2个里程碑-vi 文件编辑模式
按i(小写字母I)#INSERT 插入 编辑模式
第3个里程碑-退出编辑模式
按esc 退出编辑模式
第4个里程碑-保存并退出
:wq #保存并退出 write quit #:英文状态下
:q! #强制退出不保存
:wq! #强制保存退出 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
查看文件内容
[root@first ~]# cat /oldboy/oldboy.txt
we are family.
[root@first ~]#
路径:/ /oldboy
/oldboy/oldboy.txt(无空格)
扩展:
[root@oldboyedu ~]# [ -f /oldboy/oldboy.txt ] && echo 1 ||
echo 0
0</pre>
6.查看文件内容 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;"> #查看文件内容
[root@first ~]# cat /oldboy/oldboy.txt
we are family.
[root@first ~]# </pre>
7.绝对路径和相对路径
绝对路径:从根开始的路径
8.删除文件或目录 rm remove
-f force 强制删除不提示
-r 递归删除 一层一层删除目录及目录内容
<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>
实际工作环境中慎用,通常mv 替换
使用的时候 危险的参数 可以放在最后
<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.移动文件或目录 mv
- 移动
<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 目录移动到 /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 移动到 /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 命令的格式 []在这个格式在[]可以省略
-字母 命令参数
()小括号 []中括号 {}大括号</pre>
11.复制文件或目录 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;"> #复制
把/etc/sysconfig/network-scripts/ifcfgens33或 ifcfg-eth0 复制到 /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.显示内容到屏幕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;"> #显示内容到屏幕 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
> 重定向符号 把信息写入到文件中
[root@css ~]# cat /oldboy/lidao.txt
oldboy
[root@css ~]#
> 重定向符号 先清空文件再把信息写入到文件中
[root@css ~]# echo alex lidao >/oldboy/lidao.txt
[root@css ~]# cat /oldboy/lidao.txt
css
[root@css ~]#
>> 追加输出重定向符号 把信息写入到文件结尾
[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;"> #创建压缩包
tar zcvf 位置/压缩包名称 你要压缩的文件或目录
z 通过gzip工具压缩
c create 创建
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 ~]# #默认解压到当前路径
[root@css ~]# pwd
/root</pre>