scp
scp进行数据复制——有没有都复制,稳定(准确)性高
- 上传——scp file root@ip:dir
- 下载——scp root@ip:file dir
##将westos文件上传到ip为28的主机中
[root@westos_server Desktop]# mkdir westos
[root@westos_server Desktop]# touch westos/file{1…9}
[root@westos_server Desktop]# ls westos/
file1 file2 file3 file4 file5 file6 file7 file8 file9
##进行文件上传工作
[root@westos_server Desktop]# scp ‘/root/Desktop/westos’ root@172.25.254.28:/root/Desktop
The authenticity of host ‘172.25.254.28 (172.25.254.28)’ can’t be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘172.25.254.28’ (ECDSA) to the list of known hosts.
root@172.25.254.28’s password:
/root/Desktop/westos: not a regular file
[root@westos_server Desktop]# scp -r ‘/root/Desktop/westos’ root@172.25.254.28:/root/Desktop
root@172.25.254.28’s password:
file1 100% 0 0.0KB/s 00:00
file2 100% 0 0.0KB/s 00:00
file3 100% 0 0.0KB/s 00:00
file4 100% 0 0.0KB/s 00:00
file5 100% 0 0.0KB/s 00:00
file6 100% 0 0.0KB/s 00:00
file7 100% 0 0.0KB/s 00:00
file8 100% 0 0.0KB/s 00:00
file9 100% 0 0.0KB/s 00:00
##将ip为18的主机上的westos文件上传到ip为28的主机中
[root@westos_client Desktop]# rm -rf *
[root@westos_client Desktop]# scp -r root@172.25.254.18:/root/Desktop/westos .
root@172.25.254.18’s password:
file1 100% 0 0.0KB/s 00:00
file2 100% 0 0.0KB/s 00:00
file3 100% 0 0.0KB/s 00:00
file4 100% 0 0.0KB/s 00:00
file5 100% 0 0.0KB/s 00:00
file6 100% 0 0.0KB/s 00:00
file7 100% 0 0.0KB/s 00:00
file8 100% 0 0.0KB/s 00:00
file9 100% 0 0.0KB/s 00:00
注意:1.在上传或下载目录时需要添加-r
rsync
数据同步——默认会忽略文件属性,连接文件,设备文件
优点:有的时候什么都不做,没有复制数据,速度比scp快
名称 | 方法 |
---|---|
同步目录 | rsync -r |
同步权限 | rsync -p |
同步文件所有人 | rsync -o |
同步文件所有组 | rsync -g |
同步连接 | rsync -l |
同步设备文件 | rsync -D |
同步文件时间戳 | rsync -t |
##新建一个文件夹,里面的文件及其组属于tian用户
[root@westos_server Desktop]# mkdir /mnt/westos
[root@westos_server Desktop]# touch /mnt/westos/file{1..4}
[root@westos_server Desktop]# useradd tian
[root@westos_server Desktop]# chmod 777 /mnt/westos/*
[root@westos_server Desktop]# chown tian.tian /mnt/westos/*
[root@westos_server Desktop]# ll /mnt/westos/*
-rwxrwxrwx. 1 tian tian 0 Jul 19 01:03 /mnt/westos/file1
-rwxrwxrwx. 1 tian tian 0 Jul 19 01:03 /mnt/westos/file2
-rwxrwxrwx. 1 tian tian 0 Jul 19 01:03 /mnt/westos/file3
-rwxrwxrwx. 1 tian tian 0 Jul 19 01:03 /mnt/westos/file4
##同步目录,将文件westos传递给ip为208的主机
[root@westos_server Desktop]# rsync -r /mnt/westos root@172.25.254.208:/root/Desktop
The authenticity of host '172.25.254.208 (172.25.254.208)' can't be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.25.254.208' (ECDSA) to the list of known hosts.
root@172.25.254.208's password:
##同步目录和权限,将文件westos传递给ip为208的主机
[root@westos_server Desktop]# rsync -rp /mnt/westos root@172.25.254.208:/root/Desktop
root@172.25.254.208's password:
Permission denied, please try again.
root@172.25.254.208's password:
##同步文件所有人,目录和权限,将文件westos传递给ip为208的主机
[root@westos_server Desktop]# rsync -rpo /mnt/westos root@172.25.254.208:/root/Desktop
root@172.25.254.208's password:
查看显示1002是tian用户的ip地址,因为在该主机中没有tian’用户
##同步文件所有人,所有组,目录和权限,将文件westos传递给ip为208的主机
[root@westos_server Desktop]# rsync -rpog /mnt/westos root@172.25.254.208:/root/Desktop
root@172.25.254.208’s password:
##创建连接
[root@westos_server Desktop]# ln -s /mnt/westos /mnt/westos1
[root@westos_server Desktop]# ls -ld /mnt
drwxr-xr-x. 3 root root 33 Jul 19 01:16 /mnt
[root@westos_server Desktop]# ls -ld /mnt/westos1
lrwxrwxrwx. 1 root root 11 Jul 19 01:16 /mnt/westos1 -> /mnt/westos
查看显示1002是tian用户的ip地址,因为在该主机中没有tian’用户
##同步连接,文件所有人,所有组,目录和权限,将文件westos传递给ip为208的主机
[root@westos_server Desktop]# rsync -rpogl /mnt/westos1 root@172.25.254.208:/root/Desktop
root@172.25.254.208’s password:
连接失效,该连接指向原来的/mnt/westos文件,现文件没有该指向
归档文件——tar
归档文件,把很多文件变成1个文件
名称 | 方法 |
---|---|
创建 | tar -c |
显示过程 | tar -v |
指定归档文件名称 | tar -f |
解档 | tar -x |
查看归档内容 | tar -t |
添加文件到归档中 | tar -r |
查看归档内容 | tar -t |
解档指定文件 | tar --get |
删除归档中的指定内容 | tar --delete |
指定解档目录 | tar -C |
##执行history后练习tar命令
##创建并指定归档名称为etc.tar
1 tar cf etc.tar /etc
2 rm -rf etc.tar
##创建,指定归档名称并显示出归档过程为etc.tar
3 tar cvf etc.tar /etc
##查看归档内容
4 tar tf etc.tar
5 touch file
##添加指定文件file到归当中
6 tar rf etc.tar file
##释放出指定文件file到当前目录中
7 tar xf etc.tar
8 rm -rf etc file
##解档指定文件file到当前目录
9 tar f etc.tar --get file
##删除归档中的指定内容
10 tar f etc.tar --delete file
11 tar xf etc.tar
##将解档文件放到指定目录
12 tar xf etc.tar -C /mnt/
13 ls /mnt/
压缩
- zip
名称 | 方法 |
---|---|
压缩 | zip -r xxx.tar.zip xxx.tar |
解压缩 | unzip xxx.tar.zip |
##归档/etc为etc.tar文档
[root@westos_server Desktop]# tar cf etc.tar /etc
tar: Removing leading `/’ from member names
##压缩文件
[root@westos_server Desktop]# zip -r etc.tar.zip etc.tar
adding: etc.tar (deflated 72%)
##解压缩,因为压缩前文档未被代替,故出现下面内容
[root@westos_server Desktop]# unzip etc.tar.zip
Archive: etc.tar.zip
replace etc.tar? [y]es, [n]o, [A]ll, [N]one, [r]ename: r
new name: rtc1.tar
inflating: rtc1.tar
源文件保存,不能打包压缩一体化
- gz
名称 | 方法 |
---|---|
压缩 | gzip ;xxx.tar.gz |
解压缩 | gunzip xxx.tar.gz |
打包压缩 | tar zcf ;xxx.tar.gz /xxx |
解压缩 | tar zxf xxx.tar.gz |
##可以直接压缩文件
[root@westos_server Desktop]# gzip etc.tar
##解压缩
[root@westos_server Desktop]# gunzip etc.tar.gz
[root@westos_server Desktop]# rm -rf *
##归档压缩一体化
[root@westos_server Desktop]# tar zcf etc.tar.gz /etc
tar: Removing leading `/’ from member names
##归档压缩一体化
[root@westos_server Desktop]# tar zxf etc.tar.gz
源文件不会保存
-bz2
名称 | 方法 |
---|---|
压缩 | bzip2 ;xxx.tar |
解压缩 | bunzip2 xxx.tar.bz2 |
打包压缩 | tar zcf ;xxx.tar.bz2 /xxx |
解压缩 | tar zxf xxx.tar.bz2 |
##归档/etc为etc.tar文档
[root@westos_server Desktop]# tar cf etc.tar /etc
tar: Removing leading `/’ from member names##压缩文件
[root@westos_server Desktop]# bzip2 etc.tar
##解压缩文件
[root@westos_server Desktop]# bunzip2 etc.tar.bz2
[root@westos_server Desktop]# rm -rf *
##归档压缩一体化
[root@westos_server Desktop]# tar jcf etc.tar.bz2 /etc
tar: Removing leading `/’ from member names
##归档压缩一体化
[root@westos_server Desktop]# tar jxf etc.tar.bz2
源文件不会保存
- xz
名称 | 方法 |
---|---|
压缩 | xz .tar.zipxxx.tar |
解压缩 | unxz xxx.tar.xz |
打包压缩 | tar Jcf xxx.tar.xz /xxx |
##归档/etc为etc.tar文档
[root@westos_server Desktop]# tar cf etc.tar /etc
tar: Removing leading `/’ from member names##压缩文件
[root@westos_server Desktop]# xz etc.tar
##解压缩文件
[root@westos_server Desktop]# unxz etc.tar.xz
[root@westos_server Desktop]# rm -rf *
##归档压缩一体化
[root@westos_server Desktop]# tar Jcf etc.tar.xz /etc
tar: Removing leading `/’ from member names
不能解压解档一体化