Copying Folders with cp -r

The "cp" command acts a little differently with directories than it does with files. To demonstrate, I'll attempt to make a copy of the "VeryImportant" directory and name it "AlsoImportant".

The command I'll try is this: "cp VeryImportant/ AlsoImportant"

When I press Enter, I get a message that says "cp: VeryImportant/ is a directory (not copied)."

What this is saying is that the cp command looked for a file to copy, but was given a directory instead. It doesn't like this because there could be a lot of files inside that directory, and it doesn't know if you want to copy all of those as well, or just the directory itself.

This might seem a little weird, but it's the way it works. So, how do you make a copy of the directory and everything that's in it? You need to use the "-r" option (which stands for Recursive, or "this directory and everything inside it as well."). This basically tells the terminal "Make a copy of this directory, and all of it's contents and give it this name." So, this time, I'll actually make a copy of the "VeryImportant" directory and name it "AlsoImportant".

The command I'll use is this: "cp -r VeryImportant/ AlsoImportant"

This time, there's no error, and if we type "ls", we see the new "AlsoImportant" directory. And if we type "ls AlsoImportant/" we'll see that the "OtherThings" directory was copied as well. (We can also verify this in the Finder.) So we made an exact copy of the "VeryImportant" directory and everything in it, and named the copy "AlsoImportant".