压缩文件的用途与技术

Linux系统常见的压缩命令

  Compress

  gzip,zcat

  bzip2,bzcat

打包命令:tar


配置本地yum源

mount /dev/cdrom /mnt


/etc/yum.repos.d/aaa.repo

[aaa]

name=localyum

baseurl=file:///mnt

enabled=1

gpgcheck=0


yum list ncopmress

yum install ncompress -y



cd /opt

cp /etc/services .

compress -v services

uncompress


compress -c -v services > services.Z

rm -rf *



cp /etc/hosts .

gzip hosts

zcat hosts.gz


gzip -d hosts.gz 解压


gzip -c hosts > hosts.gz


bzip2 hosts


bzip2 -d hosts.bz2


bzip2 -c hosts > hosts.bz2


bzcat  hosts.bz2


rm -rf hosts.bz2


zip hosts.zip hosts    zip压缩

unzip hosts.zip


打包命令:tar

tar cvf hosts.tar hosts

源文件保留


tar cvf hosts.tar hosts --remove-files 不保留源文件


tar tvf hosts.tar 不解压查看归档内容


tar xvf hosts.tar


tar xvf hosts.tar -C  aa/ 解压到指定目录


cp /etc/services /etc/passwd /etc/hosts .

tar cvf xx.tar * --remove-files

tar xvf  xx.tar hosts


tar调用gzip or bzip2

tar zcvf xx.tar *    

tar zxvf xx.tar.gz

rm -rf xx.tar.gz


tar jcvf xx.tar.bz2 * --remove-files

tar jxvf xx.tar.bz2 解压缩


tar jxvf xx.tar.bz2 hosts 只解压hosts


完整备份工具: dump


完全备份 0

增量备份

差异备份


dump -0




光盘写入工具:

dd if=/dev/zero of=file1 bs=1M count=1

创建3个文件

mkisofs -o xx.iso file1 file2 file3



cp /dev/cdrom xxx.iso

mount -o  loop xxx.iso /mnt


其他常见的压缩与备份工具


dd if=/dev/sda3 of=test



拷贝file1,4到/opt


find -name 'file*' |cpio -o > xx.cpio  -o打包

cpio -iu < xx.cipo  解压档 -i解包