What is the difference among following path patterns in Linux
cp ./ [destination-path]
cp ./. [destination-path]
cp ./* [destination-path]
cp ./** [destination-path]
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The first two would make more sense with a recursive copy, i.e.
cp -r. The difference comes up if the source is a named directory, and the destination exists. Of these:
cp -r src/ dest cp -r src/. dest
the first would copy
dest/src and files within it (
dest/src/a), while the latter copies the contents of
In the other two, the shell expands the glob, so the contents of the directory (except dotfiles) are copied even without
cp ./* dest cp ./** dest
In the first, the shell expands
./* to the list of filenames in the current directory (except those starting with a dot), and
cp copies them. In the second, shells supporting it would expand
./** to a recursive listing of filenames, and again
cp would copy the files it was listed.
** works at least in Bash if
shopt -s globstar is set, in ksh with
set -o globstar.
Neither Bash or ksh includes files or directories with names starting with dot in the result of
**, regardless of which level in the tree they appear, so using that is not a very good way to make a complete copy of a full directory structure;
cp -r . dest would copy dotfiles too.
shopt -s dotglob which unhides dotfiles with both
**, I'm not sure if ksh has a similar feature.