『1-9』Linux之系统中的文件传输

Linux之系统中的文件传输

实验环境

而要两台主机并保证这两台主机是可以通信的
node26:172.25.254.26
node126:172.25.254.126
node26&node126
systemctl disable --now firewalld
systemctl stop firewalld

一、scp命令

scp 本地文件 远程主机用户@远程主机ip:远程主机目录的绝对路径
scp 远程主机用户@远程主机ip:远程主机文件的绝对路径 本地文件
实验步骤:
1.在node126建立实验素材
touch westos
mkdir westosdir
2.测试
a.把本地文件复制到远程主机(上传)
远程复制文件

[root@node126 test]# touch westos
[root@node126 test]# mkdir westosdir

在这里插入图片描述

[root@node126 test]# scp westos [email protected]:/root/Desktop
[email protected]'s password: 
westos                                        100%    0     0.0KB/s   00:00    
[root@node126 test]# 

在这里插入图片描述远程复制目录
在这里插入图片描述

[root@node126 test]# scp -r westosdir [email protected]:/root/Desktop
[email protected]'s password: 
file1                                         100%    0     0.0KB/s   00:00    
file2                                         100%    0     0.0KB/s   00:00    
[root@node126 test]# 

在这里插入图片描述``

『node26』

[root@node26 ~]# scp -r /etc/ [email protected]:/mnt

在这里插入图片描述

[root@node26 ~]# tar cf etc.tar /etc/
tar: Removing leading `/' from member names
[root@node26 ~]# du -sh etc.tar 
27M	etc.tar
[root@node26 ~]# 

速度差异惊人。

[root@node26 ~]# scp etc.tar [email protected]:/mnt
[email protected]'s password: 
etc.tar                                       100%   27MB 189.5MB/s   00:00    
[root@node26 ~]# 
[root@node126 ~]# du -sh /etc/
30M	/etc/
[root@node126 ~]# du -sh /mnt/etc.tar 
27M	/mnt/etc.tar
[root@node126 ~]# 

文件的归档和压缩

1. 文件归档

tar c 创建
tar f指定文件名称
tar x解档
tar v现实过程
tar t查看
tar r向归档文件中添加文件
tar --get解档指定文件
tar --delete 删除指定文件
tar-C指定解档路径
tar -P don’t remove “/”

tar c 创建 ##tar中,/etc表示目录本身,/etc/表示目录及其子目录
tar f指定文件名称 ##不单独使用
在这里插入图片描述刚刚在实验中,

[root@westos_student26 test]# tar cf westos.tar /ect 

然后
在这里插入图片描述

我查看了westos.tar,空的。tar中,/etc表示目录本身,/etc/表示目录及其子目录

[root@node26 ~]# tar tf westos.tar /etc/  ##错的,不存在这种用法
tar: westos.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

tar x解档

[root@node26 mnt]# tar xf westos.tar 

在这里插入图片描述

tar v现实过程

[root@node126 ~]# tar cvf etc.tar /etc/

在这里插入图片描述##无提示

[root@node26 mnt]# tar cf etc123.tar /etc/ 
tar: Removing leading `/' from member names
[root@node26 mnt]# 

tar t查看

[root@node26 mnt]# tar tf westos.tar 

在这里插入图片描述
tar r向归档文件中添加文件

[root@node26 mnt]# tar rf westos.tar 444
[root@node26 mnt]# tar tf westos.tar 

在这里插入图片描述

tar --get解档指定文件

[root@node26 mnt]# tar f westos.tar  --get etc/hostname

在这里插入图片描述

tar --delete 删除指定文件

[root@node26 mnt]# tar f westos.tar --delete 444
[root@node26 mnt]# tar tf westos.tar

在这里插入图片描述
444文件不见了

tar-C指定解档路径

[root@node26 mnt]# tar xf westos.tar -C /opt
[root@node26 mnt]# ll /opt/

在这里插入图片描述

tar -P don’t remove “/”

[root@node26 mnt]# tar -Pcf  westetc.tar /etc/
[root@node26 mnt]# tar tf westetc.tar 

在这里插入图片描述

du -sh /etc 文件大小查询命令

[root@node26 mnt]# du -sh /etc
30M	/etc
[root@node26 mnt]# 


2.文件的压缩

//zip

[root@node26 mnt]# zip -r westos.tar.zip westos.tar 
  adding: westos.tar (deflated 77%)
[root@node26 mnt]# 

在这里插入图片描述在这里插入图片描述

[root@node26 mnt]# rm westos.tar -fr
[root@node26 mnt]# ll
total 6436
-rw-r--r--. 1 root root 6587087 Jan 29 07:01 westos.tar.zip
[root@node26 mnt]# 
[root@node26 mnt]# unzip westos.tar.zip 
Archive:  westos.tar.zip
  inflating: westos.tar              
[root@node26 mnt]# 

在这里插入图片描述

gzip

需对tar文件进行操作
gzip

gunzip
etc.tar.gz后缀名
su -sh xxx.tar.gz 文件大小查询

gzip

[root@westos_student26 test]# gzip etc.tar 

在这里插入图片描述
gunzip

[root@westos_student26 test]# gunzip etc.tar.gz 

在这里插入图片描述文件大小对比
在这里插入图片描述
/etc/压缩速度: 瞬间
/etc/解压速度: 瞬间

bz2

bzip2
bunzip2
etc.tar.bz2
``

bzip2

[root@westos_student26 test]# bzip2 etc.tar 

在这里插入图片描述

bunzip2

[root@node26 mnt]# bunzip2 westos.tar.bz2 

在这里插入图片描述

etc.tar.bz2

[root@node26 mnt]# du -sh westos.tar.bz2 
4.8M	westos.tar.bz2
[root@node26 mnt]# 

xz

xz
unxz
westos.tar.xz

[root@node26 mnt]# xz westos.tar

在这里插入图片描述unxz

[root@node26 mnt]# unxz westos.tar.xz 

在这里插入图片描述

westos.tar.xz

[root@node26 mnt]# du -sh westos.tar.xz 
4.0M	westos.tar.xz
[root@node26 mnt]# 

tar z

[root@node26 mnt]# tar zcf etc.tar.gz /etc/
tar: Removing leading `/' from member names

在这里插入图片描述

[root@node26 mnt]# tar zxf etc.tar.gz 

在这里插入图片描述

tar j

[root@node26 mnt]# tar jcf etc.tar.bz2 /etc/
tar: Removing leading `/' from member names

在这里插入图片描述

[root@node26 mnt]# tar jxf etc.tar.bz2 

在这里插入图片描述

tar J

[root@node26 mnt]# tar Jcf etc.tar.xz /etc/
tar: Removing leading `/' from member names

在这里插入图片描述

[root@node26 mnt]# tar Jxf etc.tar.xz 

在这里插入图片描述

三、rsync

rsync -r 复制目录
rsync -l 复制链接
rsync -p 复制权限
rsync -t 复制时间戳
rsync -o 复制拥有者
rsync -g 复制拥有组
rsync -D 复制设备文件
实验环境
在westos_node1中
watch -n1 ls -lR /root/Desktop
在rhel8中

[root@node126 ~]# touch /root/Desktop/file{1..5}

在这里插入图片描述

[root@node126 ~]# chmod 777 /root/Desktop/*

在这里插入图片描述

[root@node126 ~]# useradd westos
[root@node126 ~]# chown westos /root/Desktop/*

在这里插入图片描述

[root@node126 ~]# ln -s /root/Desktop/file1 /root/Desktop/file

在这里插入图片描述

『node26』执行:
在这里插入图片描述

执行命令效果:
rsync -r##只同步目录中的文件 /目录/

[root@node26 ~]# rsync -r [email protected]:/root/Desktop/ /mnt
[email protected]'s password: 
skipping non-regular file "file"
[root@node26 ~]# 

在这里插入图片描述rsync -r 同步目录本身及其目录中的文件 /目录

[root@node26 ~]# rsync -r [email protected]:/root/Desktop /mnt
[email protected]'s password: 
skipping non-regular file "Desktop/file"
[root@node26 ~]# 

在这里插入图片描述

rsync -l 复制链接

[root@node26 ~]# rsync -rl [email protected]:/root/Desktop/ /mnt
[email protected]'s password: 
[root@node26 ~]# 

在这里插入图片描述

rsync -p 复制权限

[root@node26 ~]# rsync -rlp [email protected]:/root/Desktop/ /mnt
[email protected]'s password: 

在这里插入图片描述

rsync -o 复制拥有者
rsync -g 复制拥有组

[root@node26 ~]# rsync -rlpog [email protected]:/root/Desktop/ /mnt
[email protected]'s password: 

在这里插入图片描述
rsync -t 复制时间戳

[root@node26 ~]# rsync -rlpogt [email protected]:/root/Desktop/ /mnt
[email protected]'s password: 

在这里插入图片描述

rsync -D 复制设备文件

[root@node26 ~]# rsync -rD [email protected]:/dev/pts /mnt
[email protected]'s password: 

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_39679699/article/details/112857481
今日推荐