Score:0

Copy file from 'root' to 'user' gives a broken link

pk flag

So. I'd like to copy one of my Java folders to my user to then copy to somewhere else (don't ask why). However, whenever I do it, even with sudo, I get a 'Broken Link' that does nothing. I've tried these things: Using terminal normally. Using nautilus normally. Using sudo and terminal. Using sudo and nautilus.

But every single time I try, it just makes me a broken link. See here: sudo cp java-1.8(etc) /home/xendyex/Desktop/files/myjavastuff java and an empty folder. or... (white app is sudo, dark is not) photo of sudo nautilus and normal nautilus with a broken link in the normal window This is probably a stupid question, but... any help? Thanks. I'm using 23.04

lrwxrwxrwx 1 root root   21 Jul 20 10:09 java-1.17.0-openjdk-amd64 -> java-17-openjdk-amd64
drwxr-xr-x 7 root root 4096 Aug  3 11:54 java-17-openjdk-amd64
lrwxrwxrwx 1 root root   20 Jul 24 21:17 java-1.8.0-openjdk-amd64 -> java-8-openjdk-amd64
drwxr-xr-x 5 root root 4096 Aug  5 18:01 java-8-openjdk-amd64

I'm trying to replace a Java version for Minecraft.

cc flag
Did you ever try adding the -r (recusion) to the copy as the error message notes?
Bodo avatar
pt flag
Please [edit] your question and explain what you want to achieve with this copying. Copy&paste the output of `ls -l /usr/lib/jvm` to your question *as text*. The file you are copying is probably a symbolic link to a subdirectory next to it, and if you copy only the link, then the copied link will be broken. [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551)
Score:0
cn flag
raj

As the output of ls -l indicates, java-1.8.0-openjdk-amd64 is not a real subdirectory, but a symbolic link to subdirectory java-8-openjdk-amd64 located in the same directory (/usr/lib/jvm in this case). Which is btw. also indicated by the arrow sign next to the folder icon in Nautilus - the arrow sign indicates it's a link.

So if you copy that link to another location, and don't copy the corresponding subdirectory java-8-openjdk-amd64 to the same location as well, the copied link will be broken, as the object it points to does not exist.

This happens because the link points to a relative name, which is resolved using the same base directory as the directory that contains the link. If the link would point to an absolute name like /usr/lib/jvm/java-8-openjdk-amd64 instead of just java-8-openjdk-amd64, it could be copied to any location without becoming broken.

You can create such link yourself, without the need to copy the original one. Go to your target directory:

cd /home/xendyex/Desktop/files/myjavastuff

and type the command:

ln -s /usr/lib/jvm/java-8-openjdk-amd64 java-1.8.0-openjdk-amd64

You have created a link java-1.8.0-openjdk-amd64 in your directory /home/xendyex/Desktop/files/myjavastuff that points to /usr/lib/jvm/java-8-openjdk-amd64.

But note this does not copy the original Java folder (if this is what you wanted to do), it only creates a link to it in another location. If you want to make an actual copy, you need to copy the actual subdirectory java-8-openjdk-amd64 and not the link.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.