UNIX/ copy directory to new directory

6k views Asked by At

I need to copy a directory and its content to a NEW directory.

Using: cp -r dir1/dir2 dir1/dir3 where dir3 is going to be created anew, it just copies the file(s) I have within dir2... It's like it copies dir2 naming it dir3. Is there any way to copy dir2 into dir3?

I need to do it with a single command.

1

There are 1 answers

2
Mike On

It's not really possible to do it in 1 command with cp. What you want is for dir3 to already exist when you do your copy. I'm not sure if there's a real reason why you have to do it in 1 command or not. You can certainly do it in one line.

mkdir dir/dir3;cp -r dir1/dir2 dir1/dir3