1

I use terminal/the command line on a daily basis for front end web development.

As an example: Today, from the command-line I was trying duplicate a project to make a responsive web page design from a non-responsive template I had created. I know you can use cp -a /source/. /dest/ like shown here to copy files but it isn't quite duplication.

Instead of copying; inside of directory X I wanted to duplicate directory A so I have directory A and directory A(1) side by side.

I know I could quickly do this in the GUI but for the sake of a streamlined workflow I got curious.

So, would copying (cp) the directory to the same folder accomplish the same thing or this also void?

Is direct duplication at the command-line not possible or is there a certain way you have to go about it?

Thanks.

  • 2
    mkdir -p path/to/original/dir2/ ; cp -r /path/to/original/dir/ /path/to/original/dir2/ should do the trick – Wayne_Yux Oct 30 '15 at 9:23
  • Please leave me a comment, if it works then I will add some explanation to the commands and add it as an answer – Wayne_Yux Oct 30 '15 at 9:59
  • @Wayne_Yux I made a dummy folder and inside made dir and then typed mkdir dir2/ ; cp -r dir1 dir2 and it worked all in one go. Thanks, I'll be sure to use this next time my terminal usage calls for it! Switching out and going through all the folders takes a bit of time compared to this! – ConstantFun Nov 1 '15 at 14:53
2

You can do it simply:

cp -r path/to/original/dir1 path/to/original/newdir1

e.g: directory_A1 does not exist but is created when specified in the command:

cp -r /home/me/Documents/directory_A /home/me/Documents/directory_A1

If you want 'directory_A(1)': Surround the second path in quotes.

cp -r /home/me/Documents/directory_A "/home/me/Documents/directory_A(1)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.