I have a directory structured like this,

| |_somefile.txt
| |_anotherfile.js
| |_anotherfile.min.js

I want to copy dir1 and dir2 to another directory. I have tried with the following command but it copies the entire content directory to the new location. I only need the directories inside content to be there.

cd ~/Desktop/new_location/
cp -r /var/www/html/content/. ./ 

Update 2


cp -r /var/www/html/content/. ./ 


cp -r /var/www/html/content/* ./ 

works fine. I have mistakenly included aonther content directory within the content directory making it /var/www/html/content/content

Update 1
Using the command posted by @Appleoddity in the first answer on a fresh directory works. But on the actual directory which I need to copy it fails. What could be the reason for this? Check the attached image.
See it works on the new directory but not on the original

cp -R /var/www/html/content/* /tmp/new_location/

. means “this” directory. * means everything in “this” directory.

  • Tried it also. But still, it copies the content directory. I read on a StackOverflow answer that I should use the . but both are not working – isuru-buddhika Feb 1 '18 at 4:45
  • @isuru-buddhika What do you mean it copies the content directory? This command will NOT create a content directory in the destination. It should copy the entire contents of the content directory. – Appleoddity Feb 1 '18 at 4:47
  • @isuru-buddhika make sure you are using capital R. Not sure if it makes a difference here. – Appleoddity Feb 1 '18 at 4:50
  • Hmm. actually, when I tested with * on a new directory it works fine. Currently, I have my script set use the * at the end. But on my old directory, it directly copies the parent directory instead of the content inside. What could be the reason for this? – isuru-buddhika Feb 1 '18 at 4:53
  • @isuru-buddhika is the old directory a symlink? – Appleoddity Feb 1 '18 at 4:57

What is your linux distro ? I use the ubuntu 16.04.3 and it works by:

cp -r /var/www/html/content/* /tmp/new_location/

-r and -R are the same results :)

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.