How to enable a symlink in Linux from command line?

Linux supports two different ways of creating symbolic links. The first method requires running the ln command and the second method requires editing a configuration file.

ln - Create a symbolic link using the ln command

The ln command shows the files in a specific location. To create a symbolic link, specify the pathname of the file/folder you want to link to after the -s flag. The -s flag stands for "symbolic" and tells the system that this is a shortcut rather than an actual file or folder.

Syntax: ln -s / <path to file/folder to be linked><path of the link to be created>

$ ln -s /home/user/Desktop/test file testlink

For example, to create a symbolic link named "backups" to the /home/user/backup folder, type:

$ sudo ln -s /home/user/Backup /home/user/Desktop/backups

Creating Hardlinks and Creating Softlinks:

When creating a symbolic link, you can choose to create a hard link or a soft link. A hard link is just a pointer to another file. A soft link is an actual copy of the file it points to.

Only create hard links if you know what you are doing. Hard links are very dangerous because if you delete the original file that the hard link points to, the hard link file will also be deleted. This means that changes made to the hard-linked file will not affect the original file.

Was this answer helpful?

« Back