I have a problem. When i copy a folder to destination for that destination has link with source folder name, the link change to directory

$cd /home/srr7
$mkdir jetty_home123 
$ln -s jetty_home123 jetty
$ ls -l
lrwxrwxrwx 1 srr7 srr7   13 Nov 27 14:12 jetty -> jetty_home123
drwxrwxr-x 2 srr7 srr7 4096 Nov 27 14:12 jetty_home123

$cp -rf /opt/jetty /home/srr7

/opt/jetty is directory and contain multiple files.

I want to keep jetty link and copy subfolder and files of /opt/jetty to /home/srr7/jetty/.

How to solve this problem.


I want to keep jetty link and copy subfolder and files of /opt/jetty to /home/srr7/jetty/

Do exactly what you say:

cp -r /opt/jetty/* /home/srr7/jetty/

where /opt/jetty/* resolves to "subfolder(s) and files of /opt/jetty".


  • /opt/jetty/* won't yield hidden directories or files, so they won't be copied.

Possible failure scenarios:

  • if /opt/jetty/ contains no non-hidden directories/files at all;
  • if /opt/jetty/ contains so many directories/files, so you get argument list too long.
  • Thanks. If there are many directory in /opt/ and many link in /home/srr7 and they are same name, i must run cp for each directory. Would you give me a one command for copy all directory in /opt/ to /home/srr7/ if link exist just copy contain of source directory to link? – srr7 Nov 27 '18 at 13:15
  • @srr7 Please take our quick tour to learn Super User is not a forum. If you have additional requirements, they should be edited into the question body. Please note in general you shouldn't significantly change requirements after one or more answers are posted. Your question mentioned "a folder" and my answer fits; now you're talking about "one command to copy all directories". Maybe rsync can do this. If you change the question too much and my answer no longer applies, I will just delete it. – Kamil Maciorowski Nov 27 '18 at 13:31
  • OK. Thanks. I think rsync solution is good answer for my problem – srr7 Nov 28 '18 at 4:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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