00 Votes

Linux: Create Symlink to a File

Question by Guest | 2017-06-26 at 16:18

I would like to create a symbolic link (symlink) to one of my files via a script. Therefore, I am searching for a bash command for the terminal that can create such a linkage for me. Can someone help me?

ReplyPositiveNegative
0Best Answer0 Votes

Links can be created using the command ln. By default, ln creates a hard link. For creating symbolic links, you have to pass the parameter s:

ln -s /path/to/file /path/to/symlink

As you can see, after ln -s, you are first passing the path to the file that should be linked and then the path to the symlink that should be created. The symlink should not exist yet, because otherwise you would get an error message.

If the symlink is already existing and you want to change or update the link to the file, you can do that with the following line:

ln -sf /path/to/file /path/to/symlink

The "f" means force and takes care of that an existing target file / symlink will be deleted before creation. If you are using the -sf option and the symlink is not existing, also -sf is just creating a new symlink. So, you can also use this option if you do not know whether there is an already existing symlink or not.
2017-06-26 at 23:30

ReplyPositive Negative
Reply

Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

PHP: File Download Script

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.