Copy a directory including hidden files
Copy a directory with its dotfiles using cp -a src/. dst/. The usual src/* glob skips hidden files, and the dot form needs no shell option.
A copy of a directory with cp -r src/* dst/ quietly leaves out every file whose name starts with a dot.
mkdir -p src dst1 dst2
touch src/app.conf src/.env
cp -r src/* dst1/
cp -a src/. dst2/
ls -A dst1
echo ---
ls -A dst2app.conf
---
.env
app.confThe trailing /. tells cp to copy the contents of the directory, including entries that begin with a dot, because the argument names the directory itself rather than expanding to a list of names. The -a option is archive mode in GNU cp: it recurses and keeps links, permissions, ownership and timestamps where it can.
Ownership is only preserved when running as root. The src/. form works in GNU and BSD cp, but -a is GNU and recent BSD; on older systems use cp -pR src/. dst/. The destination must already exist, or cp creates it from the source name rather than copying the contents into it.