To copy the contents of one directory into another, I can use the following:
cp -Rip source-dir/ ../destination-dir/
However, it seems that using the trailing slash at the end of source directory when using cp
and mv
commands is somewhat discouraged.
No trailing slash on source directory
You should not put a trailing slash on the source directory:
The point is relevant to
cp
- but also tomv
, where it is much more important.I'll cite the warning from the manual - note that it's not found in the man page, but in the info page
info coreutils 'mv invocation'
:Warning: Avoid specifying a source name with a trailing slash, when it might be a symlink to a directory. Otherwise, 'mv' may do something very surprising, since its behavior depends on the underlying rename system call. On a system with a modern Linux-based kernel, it fails with 'errno=ENOTDIR'. However, on other systems (at least FreeBSD 6.1 and Solaris 10) it silently renames not the symlink but rather the directory referenced by the symlink.
Is it really so? And if the answer is "yes", what is the recommended way to copy the contents of a directory?