Linux基础命令(2)

(2) 备份与恢复文档
1.使用压缩和解压缩工具
(1)gzip
默认会删除原文件
-d 解压缩
-#: 指定压缩比,压缩比越小,速度越大
解压:gunzip
例:
压缩文本a.txt
[root@localhost~]#gzip a.txt
[root@localhost~]# ls -lh a.txt.gz
-rw-r--r-- 1 root root 30 Nov 11 20:07 a.txt.gz
解压文档a.txt
[root@localhost~]#gzip -d a.txt
-rw-r--r-- 1 root root 4 Nov 11 20:07 a.txt
[root@localhost~]#gunzip a.txt.gz
[root@localhost~]# ls -lh a.txt
-rw-r--r-- 1 root root 4 Nov 11 20:07 a.txt(2)bzip2

(2)bzip2
-d:解压
-#:指定压缩比
-k:保留原文件
解压缩:bunzip2
例:
压缩文档a.txt
root@localhost~]# bzip2 a.txt
[root@localhost~]# ls -lh a.txt.bz2
-rw-r--r-- 1 root root 96 Nov 11 20:16 a.txt.bz2
解压文档a.txt
[root@localhost~]# bzip2 -d a.txt.bz2
[root@localhost~]# ls -lh a.txt
-rw-r—r—1 root root 1.4K Nov 11 20:16 a.txt
[root@localhost~]# bunzip2 a.txt.bz2
[root@localhost~]# ls -lh a.txt
-rw-r—r—1 root root 1.4K Nov 11 20:16 a.txt

2.使用tar 归档和释放工具.
Tar :既可以打包,又可以压缩
tar 选项 包名 打包的文件或目录 (切记:一定要注意语法格式,先是打包后的名字,然后才是要打包的东西)
参数:
-c(--create): 创建归档文件
-f(FILE.tar): 操作的归档文件,指定文件,一般后面跟包名
-x: 展开归档
--xattrs: 归档时,保留文件的扩展属性信息
-t: 不展开归档,直接查看归档了哪些文件,不解包查看包中的内容
-C:解压时指定路径
-r:向包中追加文件
-v:显示详细过程
-z:表示使用gzip压缩方式压缩或者解压缩
-j:表示使用bzip2压缩方式压缩或者解压缩
例:
制作.gz格式的归档包
[root@localhost~]# tar zcvf etc.tar.gz /etc
tar: Removing leading /' from member names<br/>/etc/<br/>/etc/fstab<br/>//省略部分内容<br/>[root@localhost~]# ls -lh etc.tar.gz <br/>-rw-r--r-- 1 root root 11M Nov 11 20:24 etc.tar.gz<br/>制作,bz2格式归档包<br/>[root@localhost~]# tar jcvf etc.tar.bz2 /etc<br/>tar: Removing leading/' from member names
/etc/
/etc/fstab
//省略部分内容
[root@localhost~]# ls -lh etc.tar.bz2
-rw-r--r-- 1 root root 8.8M Nov 11 20:27 etc.tar.bz2

(2)从归档文档中恢复数据
①.gz
[root@localhost~]# tar zxf etc.tar.gz -C /
[root@localhost~]# ls -lh /etc
total 1.4M
//省略部分内容
②.bz2
[root@localhost~]# tar jxf etc.tar.bz2 -C /
[root@localhost~]# ls -lh /etc
total 1.4M
//省略部分内容

3.使用vi文本编辑工具
在vi编辑器中的常用命令
按i进入输入模式,按esc回到命令模式,按:进入末行模式,按esc回到命令模式

(1)命令模式的基本操作
1)模式切换
a:在当前光标位置之后插入内容
A:在当前光标所在行尾插入内容
o:在当前光标位置之后插入内容
O:在当前光标位置行首插入内容
i:在当前光标的后面插入新行
I:在当前光标的前面插入新行
2)移动光标
 光标方向移动:↑ ↓ ← →(同样可在末行模式中使用)

 翻页移动:Page Down或Crtl+F向下翻页 PageUp或Crtl+B向上翻页(同样可在末行模式中使用)
 行内快速跳转:Home键或^跳转到本行行首,End键或$跳转到本行行末(同样可在末行模式中使用)
 行间快速跳转:
1g或gg:首行
G:末行
#g:第#行
3)复制,黏贴和删除
复制:
yy:复制当前整行
#yy:复制当前光标开始得#行内容
p:黏贴
删除:
Del键:删除当前光标处内容
dd:删除当前整行
#dd:删除从当前光标开始的#行内容
d^:当前光标到行首的所有字符
d$:当前光标到行尾的所有字符
4)查找文件内容
/+指定字符串:查找指定字符串
n:移动到下一个查找结果
5)撤销编辑及保存和退出
u:取消最近一次操作并恢复操作结果
U:取消对当前行所做的所有操作
ZZ:保存当前的文件内容并退出vi编辑器
(3) 末行模式中的基本操作
1) 保存文件及退出vi编辑器
2) 打开新文件或者读取其他文件内容
3) 替换文件内容

猜你喜欢

转载自blog.51cto.com/13468179/2315601