rsync "no such file or directory" when using wildcard

6,278

Solution 1

To copy a folder to another using rsync simply do

rsync -a /source/folder/path/ /destination/folder/path/

In your case,

rsync -a "$folder64/Pictures/" "$folder65/Pictures/"

It's the trailing / on the source that is significant.

When you use $folder64/Pictures/* it is possible that you don't copy the contents of the single folder, since the command line arguments expands into a list of items in the source folder matching the * filename globbing pattern, and this usually does not match hidden files or folders.

In your specific case, you get the error message "No such file or directory". This means that the directory that you specified as source simply does not exist, or that is empty. If it's empty, this causes the * to remain unexpanded and rsync is unable to find the given file (called *) to sync.

Solution 2

Are you perhaps using an alias to rsync which involves noglob? Some shell config frameworks set that for you (e.g. prezto for zsh). I experienced the same behavior, you can either:

  1. unset the alias (unalias rsync)
  2. type the full path (/usr/bin/rsync [etc.], probably)
  3. or use command rsync [etc.]

to circumvent it.

Share:
6,278

Related videos on Youtube

DisplayName
Author by

DisplayName

Updated on September 18, 2022

Comments

  • DisplayName
    DisplayName over 1 year

    I am trying to use rsync to copy the contents of a folder to another folder. This is the command I am using for this.

    rsync -v -r $folder64/Pictures/* $folder65/Pictures/
    

    And here is the error code.

    building file list ... rsync: link_stat "/Volumes/HD/Users/jol/Pictures/*" failed: No such file or directory (2)
    done
    

    I get this with a lot of folders, that do contain items. Sometimes it, for example if I just create something on the desktop.

    • mleonard
      mleonard over 8 years
      Why the wildcard? rsync -v -r foo/ bar/ will copy the contents of foo into bar just fine. Be aware that -r alone will not copy symlinks and not keep users, permissions etc. In most cases you will prefer -a to -r.
    • DisplayName
      DisplayName over 8 years
      @Dubu, not true, it just copies the entire folder into another folder.
    • mleonard
      mleonard over 8 years
      Note the trailing slash in foo/. This denotes that the contents of foo should be synced and not the directory itself. rsync is quite picky about those trailing slashes.
    • DisplayName
      DisplayName over 8 years
      @Dudu Yeah, I did run it with a / at the end. But I'm on OSX, using rsync 2.6.9. Maybe it's different from your (I assume) GNU version?
    • jtniehof
      jtniehof over 7 years
      Trailing / syncs the root of the transfer OMM as well (rsync 3.1.1, Ubuntu). If the source is on a remote I can use the wildcard to avoid this, but not with a local source.