I'm am attempting to write a script that will copy files created in the last 24 hours AND be of a specific file-type (*.png).

The command I have tried is:

rsync -avz --ignore-existing --include='*.png' --exclude='*' \
 --files-from=<(ssh user@remote1 'find /home/admin/Backup/ -mtime -1 -type f -exec basename {} \;') \
  user@remote1:/home/admin/Backup/ /Repository/

This works for *.png files in the Backup directory however the command fails when the files are two or three folders deep i.e. located in /home/admin/Backup/folder1/folder2/ The error I get is

link_stat '/home/admin/Backup/example.png' failed: No such file or directory (2)

That is because basename {} is chopping off the location when it returns the result to rsync. So I tried removing basename {} and I get this:

link_stat '/home/admin/Backup/home/admin/Backup/folder1/folder2/example.png' failed: No such file or directory (2)

It's like rsync is appending the source directory and I don't know how to fix it. Anybody know how to fix this or perhaps I am just going about pulling this file off the remote server the wrong way?

  • Is your version find allow use -printf "%P\n" instead -exec basename {} \; ?
    – Costas
    Jan 23, 2015 at 22:25

1 Answer 1


man rsync says about --files-from:

  The  filenames  that  are read from the FILE are all relative to
  the source dir -- any leading slashes are removed  and  no  ".."
  references  are  allowed  to go higher than the source dir.  

So try making the paths output by find relative:

rsync -avz ... --files-from=<(ssh user@remote1 'cd /home/admin/Backup/; find . -mtime -1 -type f -name "*.png")

Or find /home/... ... -printf "%P\n", since %P in GNU find is:

File's name with the name of the command line argument under which it was found removed.

I have taken the liberty of adding in -name "*.png" since I don't see why rsync should do the filtering when find is capable of it and is already being used.

  • Thanks! This works except when the files are synced it copies the directories as well. What I mean is that instead of placing the .png files in /Repository/ it places them into /Repository/folder1/folder2/ is there a way to just put them into the same directory?
    – Sam
    Jan 25, 2015 at 23:42
  • @Sam try the --no-implied-dirs option.
    – muru
    Jan 25, 2015 at 23:49
  • hmm thought that would work, same results though. Here is what I am doing:rsync -avz --ignore-existing --files-from=<(ssh user@remote1 'cd /home/admin/Backup/;' 'find . -name "*.png" -type f -mtime -1 -printf "%P\n";') --no-implied-dirs user@remote1:/home/admin/Backup/ /Repository/
    – Sam
    Jan 25, 2015 at 23:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .