Linux文件的传输

一.rsync复制命令
1.scp与rsync的比较
(1)scp:复制时文件为一个一个复制,复制的为目录下的文件;复制的数据比较完整
(2)rsync:复制的速度比较快,容易忽略文件的目录链接文件属性等等
在这里插入图片描述
2.rsync文件信息的同步
rsync -r ##同步目录
在这里插入图片描述
-p ##同步权限
在这里插入图片描述
-o ##同步文件所有人
在这里插入图片描述
-g ##同步文件所有组
在这里插入图片描述
-l ##同步链接
-D ##同步设备的文件
-t ##同步文件的时间戳
在这里插入图片描述

二.文件的归档
将一个目录变成一个文件加快文件查看速率
tar -c ##创建
-v ##显示过程
-f ##指定归档文件的名称
-x ##解档
-t ##查看归档文件的内容
-r ##添加文件到归档中
–get ##解档指定文件
–delete ##删除归档中的指定文件
–C ##指定解档目录
1. tar cf ##创建

[root@localhost Desktop]# tar cf etc.tar /etc  
tar: Removing leading `/' from member names
[root@localhost Desktop]# ls
etc.tar

2.tar -rf ##添加文件并归档

[root@localhost Desktop]# tar -rf etc.tar file  ##添加文件
tar: file: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors  ##文件不存在则会产生报错

3.touch file ##创建文件

[root@localhost Desktop]# touch file 
[root@localhost Desktop]# tar rf etc.tar file  ##添加文件并归档,此时etc.tar中会有file文件

4. tar xf ##将文档解压

[root@localhost Desktop]# tar xf etc.tar  
[root@localhost Desktop]# ls
etc  etc.tar  file                 ##桌面上产生etc普通目录
[root@localhost Desktop]# rm -fr etc

5.tar -f xx --get ##指定拿出

[root@localhost Desktop]# tar -f etc.tar --get file  
[root@localhost Desktop]# ls
etc.tar  file
[root@localhost Desktop]# rm -fr file    

三.文件的压缩
1.文件的压缩及解压
(1)文件压缩为zip格式并解压
格式:zip -r 文件.zip文件
unzip 文件.zip

[root@localhost Desktop]# tar cf etc.tar /etc
tar: Removing leading `/' from member names
[root@localhost Desktop]# zip -r etc.tar.zip etc.tar
  adding: etc.tar (deflated 72%)
[root@localhost Desktop]# du -sh etc.tar.zip
15M	etc.tar.zip
[root@localhost Desktop]# du -sh etc.tar
57M	etc.tar
[root@localhost Desktop]# rm -fr etc.tar
[root@localhost Desktop]# ls
etc.tar.zip  tar  tar~  压缩
[root@localhost Desktop]# unzip etc.tar.zip
Archive:  etc.tar.zip
  inflating: etc.tar                 
[root@localhost Desktop]# ls
etc.tar  etc.tar.zip  tar  tar~  压缩
[root@localhost Desktop]# rm -fr etc.tar.zip

(2)文件压缩为gz格式并解压
格式:gzip 文件
gunzip 文件.gz

[root@localhost Desktop]# gzip etc.tar
[root@localhost Desktop]# ls
etc.tar.gz  tar  tar~  压缩
[root@localhost Desktop]# du -sh etc.tar.gz
8.4M	etc.tar.gz
[root@localhost Desktop]# gunzip etc.tar.gz
[root@localhost Desktop]# ls
etc.tar  tar  tar~  压缩

(3)文件压缩为bzip格式并解压
格式:bzip2文件
bunzip2 文件.bz2

[root@localhost Desktop]# bzip2 etc.tar
[root@localhost Desktop]# ls
etc.tar.bz2  tar  tar~  压缩
[root@localhost Desktop]# du -sh etc.tar.bz2
13M	etc.tar.bz2
[root@localhost Desktop]# bunzip2 etc.tar.bz2
[root@localhost Desktop]# ls
etc.tar  tar  tar~  压缩

(4)文件压缩为xz格式并解压
格式:xz 文件
unxz 文件.xz

[root@localhost Desktop]# xz etc.tar
[root@localhost Desktop]# du -sh etc.tar.xz 
8.0M	etc.tar.xz
[root@localhost Desktop]# unxz etc.tar.xz
[root@localhost Desktop]# ls
etc.tar  tar  tar~  压缩  压缩~

2.文件打包同时并压缩随后解压
格式:
tar zcf xxx.tar.gz /xxx ##压缩为gz模式
tar Jcf xxx.tar.xz /xxx ##压缩为xz模式
tar jcf xxx.tar.bz2 /xxx ##压缩为bz2模式

[root@localhost Desktop]# rm -fr etc.tar
[root@localhost Desktop]# tar zcf etc.tar.gz /etc
tar: Removing leading `/' from member names
[root@localhost Desktop]# ls
etc.tar.gz  tar  tar~  压缩  压缩
[root@localhost Desktop]# tar jcf etc.tar.bz2 /etc/
tar: Removing leading `/' from member names
[root@localhost Desktop]# tar Jcf etc.tar.xz /etc/
tar: Removing leading `/' from member names

3.查看各种压缩方式的压缩能力

[root@localhost Desktop]# du -sh etc.tar*
13M	etc.tar.bz2
8.4M	etc.tar.gz
8.0M	etc.tar.xz

猜你喜欢

转载自blog.csdn.net/weixin_44822212/article/details/89054326