Bash "cp -R" not copying one file

I'm writing up a bash script to copy all the contents of a directory to somewhere else and verify with a checksum of all files. Everything seems to work except that the md5sum fails because it's missing one file.

Here is the copy command:

if [ ! -d "$DESTINATION" ]; then
  mkdir $DESTINATION
fi
cp -R --copy-contents $SOURCE/* $DESTINATION &&
sleep 1

Here is the portion that checks the hash:

(find $SOURCE -type f -exec md5sum {} \; | sort -k 2 | cut -d ' ' -f 1 | md5sum | cut -d ' ' -f 1) > $SOURCE1CS
(find $DESTINATION -type f -exec md5sum {} \; | sort -k 2 | cut -d ' ' -f 1 | md5sum | cut -d ' ' -f 1) > $DEST1CS

There is a folder called "Arduino" which contains a bunch of other files. The file the command fails to copy is called "._Arduino". If it makes any difference, it is the first file at the top of the list. There are other files with that prefix which are included. There may also be other missing files, but I'm not sure. For now I can only find the one.

What am I missing that cp isn't doing?
Actually... I see now that -r and --copy-contents could be the problem. Should I be using -a instead?

try
copy -r -U "$SOURCE/.*" "$DESTINATION"
cp -r -U "$SOURCE/*" "$DESTINATION"

both statements are needed. cp wont cp hidden files unless you specify "/.*"
-U means update if source is newer than destination

2 Likes

TL;DR: the * wildcard does not match hidden files.

Pulled from here: https://forums.opensuse.org/showthread.php/401651-Problem-copying-hidden-files-with-cp

1 Like

You can simplify that abit and use cp -r -U "$SOURCE/*" "$SOURCE/.*" "$DESTINATION".
but yea you're right on the money since the * only describes the pre . , and *.* doesn't match the nothing .xyz hidden pattern either.

Thank you all. I didn't know I could copy it as a directory, since it's the root of a volume. I forgot I could add a "/." to it.

cp -a "$SOURCE/." "$DEST" worked, though I ended up going with rsync instead, which also works.