2019独角兽企业重金招聘Python工程师标准>>>

http://www.cnblogs.com/paul8339/p/7802450.html

1,在需要对大量小文件进行移动或复制时,用cp、mv都会显得很没有效率,可以用tar先压缩再解压缩的方式。 
  

2,在网络环境中传输时,可以再结合nc命令,通过管道和tcp端口进行传输。 
 nc和tar可以用来快速的在两台机器之间传输文件和目录,比ftp和scp要来得简单的多。 
 由于nc是一个超轻量的命令,所以一般busybox都会集成它。当一个linux终端,比如linux pda, 
 通过usblan的方式连接到另一台linux主机的时候,这样的嵌入式终端上一般不会集成ftp server, ssh server 
 这样比较笨重的服务,这个时候, nc可能成为唯一的上传手段。 
  

比如将机器A上的mytest目录上传到到机器 B(192.168.0.11)上,只需要: 
  

在机器B上,用nc来监听一个端口,随便就好,只要不被占用;并且将收到的数据用tar展开。-l代表监听模式。

nc -l 6666 |tar -C /target_dir -zxf -

然后,在A上通过nc和 tar发送test目录。使用一致的6666的端口。

tar -zcvf - mytest |nc 192.168.0.11 6666

Sometimes a simple cp -a command is a very painful and slow process. It's true that -v (verbose) option can give you some information on the details of the copy process, but not normally the progress of it. In fact, cp -a is a quite slow process that sometimes is faster (and safer) implemented by tar, for example:

$ tar cf - . | (cd /dst; tar xvf -)

Usually faster, and more verbose. Another commands such as pv can help you too, to monitor the progress of a copy between two directories, for example:

$ tar cf - . | pv | (cd /dst; tar xf -)
2,06GB 0:00:09 [ 194MB/s] [  <=>                     ]

But copying several gigabytes/terabytes of data and many files between quite old NFS disks is painful via cp. Let's see two alternatives for:

  • Monitoring the progress of the copy and the copied files.
  • Skipping to next file before an error (gcp)
  • Syncing directories (rsync)
  • Copying files via network (rsync)

One of the better commands for doing copies is rsync, that allows you to synchronize two directories, and in this sense src/ can have live data, that incrementally is synced to dst/ in several executions of the command

$ rsync --info=progress2 -auvz ~/Music/ /data/music/

giving a result like this:

Jake Bugg - Jake Bugg Album 2012/
Jake Bugg - Jake Bugg Album 2012/01 - Lighting Bolt.mp31,913,897,967  15%   22.79MB/s    0:01:20 (xfr#277, ir-chk=1019/1825)
Jake Bugg - Jake Bugg Album 2012/05 - Simple As This.mp31,936,698,070  15%   22.80MB/s    0:01:21 (xfr#281, ir-chk=1015/1825)

You can also use it with -n option to perform a dry run (this is more used than the skype test call), that checks and lists the differences between the two given directories. You can use it too with "-e ssh" user@host:dst/ or without --info option in older versions of rsync. It is slower for copying but it does a lot of useful things such syncing, checkings md5sums.... You will remember rsync if something goes bad.

Another fantastic command for copy is gcp. Besides of progress estimation, gcp does not copy when the file exists, skips to the next file if occurs an error, and all the fails are written to a journal file.

$ gcp -rv ~/Music/* /data/music/
Copying 13.53 GiB   2% |#                                  | 165.50 MB/s ETA:  0:01:25

Please check journal: /home/cesar/.gcp/journal

$ cat /home/cesar/.gcp/journal/home/cesar/Music/Alabama Shakes-Boys & Girls (2014)/01 - Alabama Shakes - Hold On.mp3
FAILED: already exists
/home/cesar/Music/Alabama Shakes-Boys & Girls (2014)/03 - Alabama Shakes - Hang Loose.mp3
FAILED: already exists

In an Alfresco context, many simple migrations (or restoring processes) are tracked via CIFS or Webdav drives. In these cases the above commands are useful. Even they can be useful, if you are doing a local copy in an Alfresco instance, for performing a later Filesystem Bulk process in Alfresco. From a system administrator point of view, when restoring huge contentstores or Lucene / SOLR indices, or moving backups, these commands can save you so much time.

Another day we took some time in alternatives for scp copies between two machines.

Some useful links for reading and just patience for copying:

  • http://www.linuxtecnico.es/2014/04/benchmark-cp-vs-tar-vs-cpio-vs-rsync.html
  • http://askubuntu.com/questions/17275/progress-and-speed-with-cp

NOTE: ~/Music and /data/music are simple tests on a local SSD disk.

转载于:https://my.oschina.net/u/179750/blog/3041591

Linux 如何快速复制文件相关推荐

  1. linux怎么复制文件夹全部内容,linux局域网怎么复制文件夹下的全部文件到另外文件夹...

    在Linux系统局域网中复制或拷贝文件我们可以用cp或者copy命令,但要对一个文件夹中的全部文件复制到另外一个文件夹中去,如何进行操作呢?linux局域网复制文件夹下的全部文件到另外文件夹的方法其实 ...

  2. linux 进目录输入密码,scp在Linux主机之间复制文件/目录不用输入密码

    scp在Linux主机之间复制文件/目录不用输入密码 把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中,假设本地主机linux(10.1.1.1 ...

  3. Linux命令(20)linux服务器之间复制文件和目录

    linux的scp命令: scp就是secure copy的简写,用于在linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器.  有时我们需要获得远程服务器 ...

  4. 【Mac OS】如何快速复制文件或文件夹路径

    前言 作为一个Mac OS系统初级使用者,很多地方需要不断的探索才能掌握,进而不断提升使用这个强大的生产力工具的能力. 在这篇简短的教程中,将介绍一个操作技巧:如何快速复制文件或文件夹路径. 平时开发 ...

  5. 快速复制文件,提高复制文件的速度

    文件的复制这是一个很日常的操作,为了完成复制的任务,需要同时打开源文件和目标文件夹,来进行频繁的切换.这样地操作不仅麻烦,而且还会容易出错.为了减少大家的麻烦,这里为大家分享快速复制文件,并在多个目标 ...

  6. macOS快速复制文件夹路径

    如何在macOS下,快速复制文件夹路径? 第一种方式 按住option + 鼠标右键 copy path或者是将"xxx"拷贝为路径名称 第二种方式 快捷键 option + co ...

  7. Linux 移动或复制文件(文件夹)

    Linux 移动或复制文件(文件夹) 命令格式: cp -rf /home/backup/default/Public/ Public/    复制/home/backup/default/Publi ...

  8. hyperv怎么复制文件到linux,Hyper-V快速复制虚拟机

    起因 在做一些实验性工作的时候,虚拟机是我们的好帮手,Windows10自带的Hyper-V是一款不错的软件,简单易用. 由于常常需要搭建集群环境,所以需要新建多台虚拟机,如果我们每台都去新建,将会非 ...

  9. linux指令快速复制粘贴[龟速更新中]

    由于有经常碰到要输入linux指令,但是却忘记了的情况.在家里我把常用的命令放到Xshell的快速命令集,但是在很多情况下不在家,可能用的他人电脑,以及在非Win环境下使用ssh时没有xshell使用 ...

最新文章

  1. 阿里云人脸属性API,我已经成功了(高兴高兴)
  2. mysql主从数据库设计_mysql数据库主从库镜像原理及配置
  3. php 跨区域,如何构造PHP的内容包括在非安全(http://)和安全(https://)区域以及跨多个目录使用?...
  4. 设计模式示例_介体设计模式示例
  5. 前端学习(1851)vue之电商管理系统电商系统vue创建项目
  6. react全局状态管理_react状态管理redux
  7. html设置窗口最小大小,调整HTML 5画布的大小以适应窗口
  8. pb string 接收dll按值返回_JavaScript 是如何工作的:JavaScript 的共享传递和按值传递...
  9. java新人面试经历_分享近两周以来的真实面试经历
  10. 微信小程序实现转义换行符
  11. dnf红眼补丁在哪下载_dnf补丁下载到哪里
  12. Http断点下载实简单讲解
  13. PE聚乙烯塑料会污染环境吗?
  14. 智能门禁(1)---几种人脸识别门禁系统设计的方案介绍
  15. oracle几何体数据类型,4.1 Oracle中空间几何体的类型
  16. 虾皮物流怎么收费?收费标准是什么?
  17. Verilog四位全加器
  18. Linux terminal 终端快捷键汇总
  19. BICC VS SIP --NGN协议的较量
  20. GHM------Gradient Harmonized Single-stage Detector 从梯度的方向来解决样本不均衡的问题

热门文章

  1. 清理qmail邮件队列
  2. 番茄花园 Ghost XP SP3 2012 06 电脑城极速装机版
  3. js中耦合与解耦问题总结
  4. 进阶实验2-3.1 海盗分赃 (25 分)
  5. 多态的含义、多态的作用及多态的详细代码实现
  6. 【一元多项式算法】设一个一元多项式采用带头结点的单链表存储,所有结点 按照升幂方式链接。设计一个算法,求两个多项式 A 和 B 的乘积,结果多项式 C 存放在新辟的空间中。
  7. 大数据技术之Hadoop(快速入门)
  8. 金融统计分析python论文_金融统计分析论文
  9. adb 操作 快速点击屏幕
  10. JAVAScript——JQuery—$ ( )