栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux第7章:系统中的文件传输

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux第7章:系统中的文件传输

系统中的文件传输 实验环境 需要 2 台主机并且保证这两台主机是可以通信的(设两台服务器的ip分别为本机A172.25.254.132,远程机B172.25.254.132.) 1.scp命令 scp是secure copy 的缩写,scp是linux系统下基于ssh登陆进行的安全的远程文件拷贝命令。linux的scp命令可以在linux服务器之间复制文件和目录。scp在机器复制的时候为了提高数据的安全性,使用了ssh连接和加密方式,如果机器之间配置了ssh免密码登陆,那么在使用scp d的时候不用输入密码. scp 本地文件 远程主机用户 @ 远程主机 ip : 远程主机目录的绝对路径 scp 远程主机用户 @ 远程主机 ip : 远程主机文件的绝对路径 本地文件 实验素材 在本机桌面建立一个文件(8笔记)目录(课程资料) 远程主机桌面文件(qwe) 复制本机文件到远程主机的桌面上  [root@westoslinux Desktop]# scp 8笔记 root@172.25.254.32:/home/westos/Desktop/   root@172.25.254.32's password:       8笔记                                        100% 6895     2.7MB/s   00:00 [root@westoslinux Desktop]# scp -q  8笔记  root@172.25.254.32:/home/westos/Desktop/   (-q传输文件时不显示速度)
root@172.25.254.32's password:  [root@westoslinux Desktop]# scp -qr 课程资料 root@172.25.254.32:/home/westos/Desktop/ (-r表示复制目录)
root@172.25.254.32's password: 复制远程主机的文件到本机的桌面上 [root@westoslinux Desktop]# scp root@172.25.254.32:/home/westos/Desktop/qwe /root/Desktop/  
root@172.25.254.32's password: 
qwe                                            100%    0     0.0KB/s   00:00   2.rsync 命令 (可以实现增量备份的工具)目的是实现本地主机和远程主机上的文件同步拷贝,也包含远程到本地两种同步方式(rsync不支持远程到远程的拷贝,scp支持,cp只能本地拷贝) rsync传输速度快于scp rsync 用法 rsync   文件            远程用户 @ 远程主机 ip : 远程主机目录 rsync   远程用户 @ 远程主机 ip : 远程主机目录     文件路径 rsync               - r ## 复制目录               - l ## 复制链接               - p ## 复制权限               - t ## 复制时间戳               - o ## 复制拥有者               - g ## 复制拥有组               - D ## 复制设备文件 实验: root@westoslinux mnt]# touch /mnt/westosfile{1..5}   切换路径/mnt/ 建立5个文件 [root@westoslinux mnt]# chmod 777 /mnt/westosfile*    设置所有文件为满权限 [root@westoslinux mnt]# chown westos.westos /mnt/westosfile*  更改所有文件的用户和用户组 显示如下
[root@westoslinux mnt]# ll
total 0
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile1
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile2
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile3
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile4
-rwxrwxrwx. 1 westos westos 0 Oct 16 11:11 westosfile5 [root@westoslinux mnt]# rsync -r /mnt root@172.25.254.32:/home/westos/Desktop  
root@172.25.254.32's password:        复制本机目录本身及文件到远程主机桌面中 [root@westoslinux mnt]# rsync -r /mnt/ root@172.25.254.32:/home/westos/Desktop
root@172.25.254.32's password:        复制本机目录里边的文件到远程主机桌面中 [root@westoslinux mnt]# rsync -pr /mnt/ root@172.25.254.32:/home/westos/Desktop(-p复制权限)
root@172.25.254.32's password:   [root@westoslinux mnt]# rsync -por /mnt/ root@172.25.254.32:/home/westos/Desktop(-o复制拥有者)
root@172.25.254.32's password:  [root@westoslinux mnt]# rsync -pogr /mnt/ root@172.25.254.32:/home/westos/Desktop(-g复制拥有组)
root@172.25.254.32's password:  [root@westoslinux mnt]# rsync -pogrt /mnt/ root@172.25.254.32:/home/westos/Desktop(-t复制时间戳)
root@172.25.254.32's password: 
   [root@westoslinux mnt]# ll
total 0
lrwxrwxrwx. 1 root   root   16 Oct 16 11:22 lee -> /mnt/westosfile1
-rwxrwxrwx. 1 westos westos  0 Oct 16 11:11 westosfile1
-rwxrwxrwx. 1 westos westos  0 Oct 16 11:11 westosfile2
-rwxrwxrwx. 1 westos westos  0 Oct 16 11:11 westosfile3
-rwxrwxrwx. 1 westos westos  0 Oct 16 11:11 westosfile4
-rwxrwxrwx. 1 westos westos  0 Oct 16 11:11 westosfile5 [root@westoslinux mnt]# ln -s /mnt/westosfile1 /mnt/lee  给westosfile1建立一个软链接到lee上 [root@westoslinux mnt]# rsync -plogrt /mnt/ root@172.25.254.32:/home/westos/Desktop(-l复制链接)
root@172.25.254.32's password: 

 

[root@westoslinux mnt]# ll /dev/pts/设备文件 
total 0
crw--w----. 1 root tty  136, 0 Oct 16 11:25 0
c---------. 1 root root   5, 2 Oct 16 08:52 ptmx

[root@westoslinux mnt]# rsync -plogrtD /dev/pts/ root@172.25.254.32:/home/westos/Desktop(-D复制设备文件)
root@172.25.254.32's password: 

 

文件的归档压缩 1. 文件归档 tar c ## 创建 f ## 指定文件名称 x ## 解档 v ## 现实过程 t ## 查看 r ## 向归档文件中添加文件 -- get ## 解档指定文件 -- delete ## 删除指定文件 - C ## 指定解档路径 - P ##don ' t remove " / " 解压到绝对路径

 [root@westoslinux mnt]# du -sh etc.tar
27M    etc.tar
[root@westoslinux mnt]# du -sh /etc/
29M    /etc/     打包好的文件大小和没有打包之前的大小

2. 文件的压缩

 压缩 不能直接对目录进行压缩  要对打包好的目录文件进行压缩

[root@westoslinux Desktop]# cd /mnt
[root@westoslinux mnt]# ls
etc.tar  media.tar zip zip -r mnt.tar.zip mnt.tar #zip格式压缩 unzip mnt.tar.zip #zip格式解压缩 [root@westoslinux mnt]# zip -r etc.tar.zip etc.tar   压缩etc.tar
  adding: etc.tar (deflated 75%) [root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar [root@westoslinux mnt]# du -sh etc.tar.zip  比较打包文件和压缩包的大小 
6.7M    etc.tar.zip [root@westoslinux mnt]# du -sh etc.tar
27M    etc.tar [root@westoslinux mnt]# rm -fr etc.tar
[root@westoslinux mnt]# ls etc.tar.zip  media.tar [root@westoslinux mnt]# unzip etc.tar.zip   解压
Archive:  etc.tar.zip
  inflating: etc.tar   

[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar

 

gzip

gzip mnt.tar  #gzip格式压缩

gunzip mnt.tar.gz #gzip格式解压缩

[root@westoslinux mnt]# gzip media.tar  
[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar.gz
[root@westoslinux mnt]# du -sh media.tar.gz
6.7M    media.tar.gz

[root@westoslinux mnt]# gunzip media.tar.gz
[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar

 

bzip2 mnt.tar   #bzip2格式压缩 bunzip2 etc.tar.bz2   #bzip2格式解压缩 [root@westoslinux mnt]# bzip2 etc.tar
[root@westoslinux mnt]# du -sh etc.tar.bz2
5.1M    etc.tar.bz2
[root@westoslinux mnt]# bunzip2 etc.tar.bz2
[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar

 

xz mnt.tar  #xz格式压缩 unxz mnt.tar.xz  #xz格式解压缩 [root@westoslinux mnt]# xz etc.tar
[root@westoslinux mnt]# ls
etc.tar.xz  etc.tar.zip  media.tar
[root@westoslinux mnt]# du -sh etc.tar.xz
4.4M    etc.tar.xz
[root@westoslinux mnt]# unxz etc.tar.xz
[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar

 

3. tar + 压缩 gzip tar zcf etc.tar.gz /etc tar zxf etc.tar.gz [root@westoslinux mnt]# tar zcf media.tar.gz /media/
tar: Removing leading `/' from member names
[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media.tar.gz
[root@westoslinux mnt]# 
[root@westoslinux mnt]# tar zxf media.tar.gz
[root@westoslinux mnt]# ls
etc.tar  etc.tar.zip  media  media.tar.gz bzip2 tar jcf etc.tar.bz2 /etc tar jxf etc.tar.bz2 xz tar Jcf etc.tar.xz /etc tar Jxf etc.tar.xzi
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/333995.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号