rsync "no such file or directory" when using wildcard
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:
- unset the alias (
unalias rsync
) - type the full path (
/usr/bin/rsync [etc.]
, probably) - or use
command rsync [etc.]
to circumvent it.
Related videos on Youtube
DisplayName
Updated on September 18, 2022Comments
-
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 over 8 yearsWhy the wildcard?
rsync -v -r foo/ bar/
will copy the contents offoo
intobar
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 over 8 years@Dubu, not true, it just copies the entire folder into another folder.
-
mleonard over 8 yearsNote the trailing slash in
foo/
. This denotes that the contents offoo
should be synced and not the directory itself.rsync
is quite picky about those trailing slashes. -
DisplayName over 8 years@Dudu Yeah, I did run it with a
/
at the end. But I'm on OSX, usingrsync
2.6.9. Maybe it's different from your (I assume) GNU version? -
jtniehof over 7 yearsTrailing / 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.
-