Linux文件在系统中传输

一、文件的传输

1.命令:scp

  scp  file  user@ip:/dir    ##把当前系统目录下的文件file复制到另一个系统目录下

  scp  user@ip:/file  dir

2.命令:rsync    ##数据的远程同步 ,可以加快传输速率

  •   常用参数:-r  ##同步目录里面的内容       -p  ##同步权限      -D  ##同步传输设备

                -o  ##同步用户                -g  ##同步组信息

                -t  ##同步时间戳              -l  ##同步链接

  •   示例:  在主机97下进行的命令rsync -r niu/ root@172.25.254.177:/mnt/的操作:
  [root@localhost mnt]# mkdir niu 

  [root@localhost mnt]# touch niu/file{1..3} 

  [root@localhost mnt]# chmod 777 niu/*

  [root@localhost niu]# chown student.student *
  [root@localhost niu]# ls -l
  total 0
  -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file1
  -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file2
  -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file3
  [root@localhost mnt]# rsync -r niu/ root@172.25.254.177:/mnt/
   在主机177里面进行查看: 
   [root@localhost mnt]# ls -l
   total 0
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file1
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file2
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file3
  •    在97主机下使用rsync -rp niu/ root@172.25.254.177:/mnt/的操作:

  

   [root@localhost mnt]# rsync -rp niu/ root@172.25.254.177:/mnt/

   在177主机下进行测试 :  (文件的权限相同的)
   [root@localhost mnt]# ls -l
   total 0
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file1
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file2
   -rwxrwxrwx 1 root root 0 Jul 26 09:00 file3
  •    在97主机下使用rsync -rpogt niu/  root@172.25.254.177:/mnt/的操作:
   [root@localhost niu]# ls -l
   total 0
   -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file1
   -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file2
   -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file3

    [root@localhost mnt]# rsync -rpogt niu/ root@172.25.254.177:/mnt/
    root@172.25.254.177's password:  

    在177主机下测试:

    [root@localhost mnt]# ls -l

    total 0
    -rwxrwxrwx 1 student student 0 Jul 26 08:49 file1
    -rwxrwxrwx 1 student student 0 Jul 26 08:49 file2
    -rwxrwxrwx 1 student student 0 Jul 26 08:49 file3
  •     进行链接的传输:

    [root@localhost niu]# ln -s file1 /mnt/niu/westos

    [root@localhost niu]# ls -l
    total 0
    -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file1
    -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file2
    -rwxrwxrwx. 1 student student 0 Jul 26 08:49 file3
    lrwxrwxrwx. 1 root    root    5 Jul 26 09:28 westos -> file1
    [root@localhost mnt]# rsync -rl niu/ root@172.25.254.177:/mnt/
    root@172.25.254.177's password:
  •     进行设备文件的传输:     
    [root@localhost mnt]# ls /dev/pts/
     0  ptmx
    [root@localhost mnt]# rsync -rD /dev/pts/ root@172.25.254.177:/mnt/
    root@172.25.254.177's password:
    在177主机下:

    [root@localhost mnt]# ls

     0  ptmx
二、归档
  •   作用:可以加快不同系统之间文件的传输,使一个目录或多个文件打包为一个文件,方便传输。(归档不代表剪切)
  •   命令:tar
  •   参数:-c   ## 创建      -v   ## 显示过程      -f   ## 指定归档的文件名称

       -t   ## 查看归档文件内容       -r    ## 添加文件到归档中     

       --get file  ## 解档指定文件    --delete  file   ##删除归档中文件

       -C    dir   ## 指定解档的目录

  •   示例:etc.tar的创建和查看结果

  

  •    添加file文件到etc.tar归档中:

 

  

 

  
  •    归档文件的拿出(默认到当前目录下):
  
  •    解档:使档案里的文件全部拿出、解档到固定目录
  
   
     

 

三、文件的压缩

【1】zip

  格式:zip -r xxx.tar.zip  xxx.tar   压缩

       unzip  xxx.tar.zip    解压

  示例:

   
 

  打包和压缩后的文件的大小:

  [root@localhost Desktop]# ls
  etc.tar  etc.tar.zip
  [root@localhost Desktop]# du -sh *
  30M    etc.tar
  16M    etc.tar.zip

【2】gz

  •   格式:gzip  xxx.tar   压缩

       gunzip  xxx.tar.gz  解压

       tar zcf  xxx.tar.gz /etc/    打包+压缩

       tar zxf  xxx.tar.gz  解压

  •   示例:(在压缩和解压过程中,只能产生一个 ) 
   
 
  •   打包和压缩后的文件的大小:
  [root@localhost Desktop]# du -sh etc.tar
  30M    etc.tar
  [root@localhost Desktop]# du -sh etc.tar.gz
  8.4M    etc.tar.gz

【3】bz2

  •   格式:bzip2  xxx.tar   压缩

       bunzip2   xxx.tar.bz2  解压

       tar jcf   xxx.tar.bz2  /etc/   打包+解压

       tar jxf   xxx.tar.bz2  解压
  •   示例: 
  
  

【4】xz

  •   格式:xz  xxx.tar   压缩

       unxz  xxx.tar.xz  解压

       tar  Jcf   xxx.tar.xz   /etc/   打包+解压

       tar Jxf  xxx.tar.xz  解压
  •   示例:
  
  

   注释:【2】【3】【4】解压打包可以一步完成

 

 


 

 

posted @ 2018-07-26 21:42  UTHN_B  阅读(610)  评论(0编辑  收藏  举报