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.
Links Types
There are two types of links in Linux/UNIX systems:
- Hard links. You can think a hard link as an additional name for an existing file. Hard links are associating two or more file names with the same node. You can create one or more hard links for a single file. Hard links cannot be created for directories and files on a different filesystem or partition.
- Soft links. A soft link is something like a shortcut in Windows. It is an indirect pointer to a file or directory. Unlike a hard link, a symbolic link can point to a file or a directory on a different filesystem or partition.
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:
ln -s [OPTIONS] FILE LINK
Symlink To a File
To create a symbolic link to a given file, run:
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:
Symlinks To a Directory
To create a symbolic link to a directory is the same as when creating a symbolic link to a file, run:
Overwriting Symlinks
If you try to create a symbolic link that already exists, the ln command will print an error message.
To overwrite the destination path of the symlink, use the -f (--force) option.
Check if symlink was created
To verify that the symlink was successfully created, use the *ls* command:
The output will look something like this:
Removing or Deleting Symlinks
To delete/remove symbolic links use either the unlink or rm command. The syntax is simple:
Removing a symbolic link using the rm command:
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