Ubuntu – Does cp not copy a specified folder

bashcp

let's say that I have a following file structure:

~/DIR1
-fileA
-DIR2
--fileB

Then, being in ~, I run this script:

cp DIR1 NEWDIR2

And just an error happens:

cp: omitting directory ‘DIR1’

I understand why nothing from DIR1 gets copied (because I didn't use -r switch that would enforce recursion) but I'd expect the DIR1 folder itself copied to NEWDIR2 (so practically a creation of a new "NEWDIR2" in ~ or a creation of ~/NEWDIR2/DIR1).

Could someone explain to me why is my expectation wrong?

Best Answer

From the GNU info page for cp:

By default, 'cp' does not copy directories. However, the '-R', '-a', and '-r' options cause 'cp' to copy recursively by descending into source directories and copying files to corresponding destination directories.

https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html#cp-invocation