read input from a file and sync accordingly

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/

Or a for-loop and copy:

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

Leave a Comment