To create a symbolic link in Linux, you can use the ln command with the -s option. Here’s the syntax:
ln -s [target_file_or_directory] [link_name]
Example
- Creating a symbolic link to a file:
ln -s /path/to/original_file.txt /path/to/symlink_file.txt
- Creating a symbolic link to a directory:
ln -s /path/to/original_directory /path/to/symlink_directory
Steps:
- Open your terminal.
- Use the
ln -scommand with the appropriate paths. - Verify the symbolic link by using the
ls -lcommand to see the link and its target.
Note
- The symbolic link (
symlink_file.txtorsymlink_directory) can be named anything you choose. - If the target file or directory is removed, the symbolic link will still exist but will point to a non-existent location (often referred to as a "broken link").
