How to create a symlink to root

Ankur S

I want to create a symlink to the root (/) folder in my home directory. However if I try this, I get

~$ ln -s /
ln: failed to create symbolic link './': File exists

I can do this using Nautilus Ctrl+D, of course, so I know it's possible.

How to do so using the terminal?

Videonauth

You're missing the name of the link, it should be:

cd ~
ln -s / root

Which then would create a symlink called root in your home directory. So the correct usage is:

ln -s <target> <link-name>

The error message you see is, that ./ always exists and a link can not be created with this name, best is to use the ln command2 with both parameters to prevent wrong linkage.

From man ln:

SYNOPSIS

(1st form) ln [OPTION]... [-T] TARGET LINK_NAME  
(2nd form) ln [OPTION]... TARGET  
(3rd form) ln [OPTION]... TARGET... DIRECTORY  
(4th form) ln [OPTION]... -t DIRECTORY TARGET...  

DESCRIPTION

In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd form, create a link to TARGET in the current directory. In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. Create hard links by default, symbolic links with --symbolic. By default, each destination (name of new link) should not already exist4. When creating hard links, each TARGET must exist. Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.

Mandatory arguments to long options are mandatory for short options too.

OPTIONS

The final parameter, <link-name>, defaults to the last part of the target. So when the target is /path/dir the link name will default to dir if not specified.1 And if you for example create ~/etc with mkdir ~/etc and then run ln -s /etc in ~ it can not create the link because the name/directory already exists.3

And you can see the link created in your home directory (here as example, of course you're free to name it whatever you like):

$ ls -l ~/root
lrwxrwxrwx 1 videonauth videonauth 1 Dez 14 00:28 root -> /

1 Thanks to @thomasrutter for pointing that out.
2 See also man link and man symlink
3 Thanks to @steeldriver for providing an example in comments.
4 Emphasised part to make text point out since it is relevant to the question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to create a symlink to root

From Dev

How to create symlink with Haskell?

From Dev

What is a symlink and how to create one?

From Dev

How to create a bashrc/zshrc symlink?

From Dev

How to create a folder symlink that has a different name?

From Dev

lighttpd: symlink as document root

From Dev

How to create a symlink to open a directory in Terminal on Mac osx?

From Dev

How to create relative symlink in Java NIO.2?

From Dev

How to create symlink from public/storage to storage/app/public in laravel?

From Dev

How to create a symlink which opens (literally) the target file

From Dev

How to create a symlink which opens (literally) the target file

From Dev

How to Create Symlink Dynamically for Dynamically Created File in a Folder

From Dev

How to create a relative symlink which works across PC

From Dev

Symlink giving "Permission denied"... to root

From Dev

Create SymLink with GPO

From Dev

Unable to create a symlink to a file

From Dev

Create symlink manually

From Dev

Create Relative Symlink Inside Relative Symlink

From Dev

ln: create symlink using another symlink

From Dev

How can I make a symlink to a directory owned by root that's readable by anything?

From Dev

How to force a symlink creation by overriding the existing symlink?

From Dev

accessing path from outside the root with symlink

From Dev

Check file exists and create a symlink

From Dev

Create symlink tree in existing directories

From Dev

Create symlink - overwrite if one exists

From Dev

Is possible to create a symlink for a remote file?

From Dev

Create a new symlink for files in a folder

From Dev

Yocto: create a symlink in an image recipe

From Dev

How to overwrite a symlink in Go?

Related Related

HotTag

Archive