# Symbolic links in Linux systems

Symbolic link, also know as a Symlink or soft link. Is a kind of shortcut that point to a specific file or directory.

There are two types of links in Linux/UNIX systems:

## How to Use the ln Command

ln is a command-line utility for creating links between files. By default, the ln command creates hard links. To create a symbolic link use, the -s (–symbolic) option.

The ln command syntax for creating symbolic links is as follows:


To create a symbolic link to a given file, run:

ln -s source_file symbolic_link

The symbolic_link parameter is optional. If you do not specify the symbolic link, the ln command will create a new link in your current directory:

To create a symbolic link to a directory is the same as when creating a symbolic link to a file, run:

ln -s /mnt/my_drive/anime ~/Videos/anime

If you try to create a symbolic link that already exists, the ln command will print an error message.

ln -s my_file.txt my_link.txt
ln: failed to create symbolic link 'my_link.txt': File exists

To overwrite the destination path of the symlink, use the -f (–force) option.

ln -sf my_file.txt my_link.txt

To verify that the symlink was successfully created, use the ls command:

ls -l

The output will look something like this:

my_link.txt -> my_file.txt

To delete/remove symbolic links use either the unlink or rm command. The syntax is simple:

unlink symlink_to_remove

Removing a symbolic link using the rm command:

rm symlink_to_remove

No matter which command you use, when removing a symbolic link not append the / trailing slash at the end of its name.

If you delete or move the source file to a different location, the symbolic file will be left broken and should be removed.



© DarknessCode - LinuxSucks