Kevin Shoesmith

There have been many occasions on which I've wanted to copy all the sub-directories and files from one directory to another directory on the command line, but I didn't want to copy the containing directory itself. I was frustrated in trying to do this using the 'cp' command, but I was finding that when I typed

cp -r directory-a/ directory-b

it would copy directory-a and its contents to directory-b, not just the contents like I wanted.

The trick is to 'cd' into the directory of the contents you want to copy into another dir and type:

cp -apv . /path/to/directory-b

That will achieve the result you want while preserving the original files permissions and ownership in the process.

Add new comment