基于Linux下的文件归档
不同系统之间的文件传输:(scp和rsync命令)
1.文件归档,就是把多个文件变成一个归档文件
tar c 创建
f 指定归档文件名称
t 显示归档文件中的内容
r 向归档文件中添加文件
--get 取出单个文件
--delete 删除单个文件
x 取出归档文件中的所有内容
-C 指定解档目录
-z gz格式压缩
-j bz2格式压缩
-J xz格式压缩
[[email protected] mnt]# cd
[[email protected] ~]# cd /root/Desktop 将建立文件路径更改到桌面
[[email protected] Desktop]# tar cf etc.tar /etc/ 将/etc/文件归档到桌面
tar: Removing leading `/' from member names

[[email protected] Desktop]# tar tf etc.tar 显示归档内容
etc/
etc/fstab
etc/crypttab 展示部分内容
[[email protected] Desktop]# tar rf etc.tar westos 向文档中添加westos
[[email protected] Desktop]# rm -rf westos 删除桌面的westos
[[email protected] Desktop]# tar xf etc.tar 取出文档所有内容
[[email protected] Desktop]# tar f etc.tar --get westos 取出westos
[[email protected] Desktop]# tar f etc.tar --get etc 取出etc
[[email protected] Desktop]# tar f etc.tar --delete westos 删除归档里面的westos
[[email protected] Desktop]# rsync -r /root/Desktop/etc.tar [email protected]:/mnt/ 将归档包移动到另外一个虚拟机。
2.压缩的四种格式以及具体操作:
gz
gzip etc.tar 压缩成gz格式
gunzip etc.tar.gz 解压gz格式压缩包
tar zcf etc.tar.gz /etc 把文件归档为tar并压缩成gz
tar zxf etc.tar.gz 解压并解档gz格式压缩包
bz2
bzip2 etc.tar 压缩成bz2格式
bunzip2 etc.tar.bz2 解压bz2格式压缩包
tar jcf etc.tar.bz2 /etc 把文件归档为tar并压缩成bz2
tar jxf etc.tar.bz2 解压并解档bz2格式压缩包
xz
xz etc.tar 压缩成xz格式
unxz etc.tar.xz 解压xz格式压缩包
tar Jcf etc.tar.xz /etc 把文件归档为tar并压缩成zx
tar Jxf etc.tar.xz 解压并解档xz格式压缩包
zip
zip -r etc.tar.zip etc.tar 压缩成zip格式
unzip etc.tar.zip 解压zip格式压缩包
第一种解压方式具体操作: