从文件中读取输入并相应地同步 [英] read input from a file and sync accordingly

查看:32
本文介绍了从文件中读取输入并相应地同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,其中包含我要复制的文件和目录列表(一行一个).现在我希望 rsync 从我的文本文件中获取此输入并将其同步到我提供的目的地.

I have a text file which contains the list of files and directories that I want to copy (one on a line). Now I want rsync to take this input from my text file and sync it to the destination that I provide.

我尝试使用 rsync 的 "--include-from=FILE""--file-from=FILE" 选项,但它只是不工作

I've tried playing around with "--include-from=FILE" and "--file-from=FILE" options of rsync but it is just not working

我也尝试在我的文件的每一行上预先修复 "+" 但它仍然不起作用.

I also tried pre-fixing "+" on each line in my file but still it is not working.

我尝试使用 rsync 手册页中概述的各种过滤器模式,但仍然无法正常工作.

I have tried coming with various filter PATTERNs as outlined in the rsync man page but it is still not working.

有人可以为我提供此用例的正确语法.我已经在 Fedora 15、RHEL 6.2 和 Ubuntu 10.04 上尝试了上述内容,但都没有奏效.所以我肯定错过了一些东西.

Could someone provide me correct syntax for this use case. I've tried above things on Fedora 15, RHEL 6.2 and Ubuntu 10.04 and none worked. So i am definitely missing something.

非常感谢.

推荐答案

根据您想要如何复制这些文件,有不止一种方法可以回答这个问题.如果您的目的是使用绝对路径复制文件列表,则它可能类似于:

There is more than one way to answer this question depending on how you want to copy these files. If your intent is to copy the file list with absolute paths, then it might look something like:

rsync -av --files-from=/path/to/files.txt//destination/path/

...这将期望路径相对于 / 的源位置,并将保留该目标下的整个绝对结构.

...This would expect the paths to be relative to the source location of / and would retain the entire absolute structure under that destination.

如果您的目标是将列表中的所有文件复制到目标位置,而不保留任何类型的路径层次结构(只是文件的集合),那么您可以尝试以下方法之一:

If your goal is to copy all of those files in the list to the destination, without preserving any kind of path hierarchy (just a collection of files), then you could try one of the following:

# note this method might break if your file it too long and
# exceed the maximum arg limit
rsync -av `cat /path/to/file` /destination/

# or get fancy with xargs to batch 200 of your items at a time
# with multiple calls to rsync
cat /path/to/file | xargs -n 200 -J % rsync -av % /destination/

或者一个 for 循环并复制:

Or a for-loop and copy:

# bash shell
for f in `cat /path/to/files.txt`; do cp $f /dest/; done

这篇关于从文件中读取输入并相应地同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆