CentOS下tar打包解压详解(解压到指定文件夹)

2019-10-13 10:18:50于丽

-z :压缩的参数

-# :与gzip 同样的,都是在计算压缩比的参数,-9 最佳,-1 最快!

范例:

范例一:将刚刚的/tmp/man.config 以bzip2 压缩

[root@linux tmp]# bzip2 -z man.config

# 此时man.config 会变成man.config.bz2 !

范例二:将范例一的文件内容读出来!

[root@linux tmp]# bzcat man.config.bz2

# 此时萤幕上会显示man.config.bz2 解压缩之后的文件内容!!

范例三:将范例一的文件解压缩

[root@linux tmp]# bzip2 -d man.config.bz2

范例四:将范例三解开的man.config 用最佳的压缩比压缩,并保留原本的文件

[root@linux tmp]# bzip2 -9 -c man.config > man.config.bz2

compress 命令

[root@linux ~]# compress [-dcr] 文件或目录

参数:

-d :用来解压缩的参数

-r :可以连同目录下的文件也同时给予压缩呢!

-c :将压缩资料输出成为standard output (输出到萤幕)

范例:

范例一:将/etc/man.config 複制到/tmp ,并加以压缩

[root@linux ~]# cd /tmp

[root@linux tmp]# cp /etc/man.config .

[root@linux tmp]# compress man.config

[root@linux tmp]# ls -l

-rw-r--r-- 1 root root 2605 Jul 27 11:43 man.config.Z

范例二:将刚刚的压缩档解开

[root@linux tmp]# compress -d man.config.Z

范例三:将man.config 压缩成另外一个文件来备份

[root@linux tmp]# compress -c man.config > man.config.back.Z

[root@linux tmp]# ll man.config*

-rw-r--r-- 1 root root 4506 Jul 27 11:43 man.config

-rw-r--r-- 1 root root 2605 Jul 27 11:46 man.config.back.Z

# 这个-c 的参数比较有趣!他会将压缩过程的资料输出到萤幕上,而不是写入成为

# file.Z 文件。所以,我们可以透过资料流重导向的方法将资料输出成为另一个档名。

# 关於资料流重导向,我们会在bash shell 当中详细谈论的啦!

dd 命令

[root@linux ~]# dd if="input_file" of="outptu_file" bs="block_size" 

count="number"

参数:

if :就是input file 啰~也可以是装置喔!

of :就是output file 喔~也可以是装置;

bs :规划的一个block 的大小,如果没有设定时,预设是512 bytes

count:多少个bs 的意思。

范例:

范例一:将/etc/passwd 备份到/tmp/passwd.back 当中

[root@linux ~]# dd if=/etc/passwd of=/tmp/passwd.back

3+1 records in

3+1 records out

[root@linux ~]# ll /etc/passwd /tmp/passwd.back

-rw-r--r-- 1 root root 1746 Aug 25 14:16 /etc/passwd

-rw-r--r-- 1 root root 1746 Aug 29 16:57 /tmp/passwd.back

# 仔细的看一下,我的/etc/passwd 文件大小为1746 bytes,因为我没有设定bs ,

# 所以预设是512 bytes 为一个单位,因此,上面那个3+1 表示有3 个完整的

# 512 bytes,以及未满512 bytes 的另一个block 的意思啦!

# 事实上,感觉好像是cp 这个指令啦~