DEV Community

Gosu Code
Gosu Code

Posted on

Mastering Symbolic Links: A Quick Guide

Hey there tech enthusiasts! Let's get started with this sweet and short guide!

What Are Symbolic Links?

Symbolic links, or symlinks, are special files that act as pointers to other files or directories. They're like shortcuts, allowing you to access a file from a different location without duplicating it.

How to Create a Symbolic Link on Unix/Linux/macOS:

1. Open the Terminal:
Use your preferred terminal application.

2. Create a file at desired location
When creating a symbolic link, you typically point it to an existing file or directory. So, you should have the original file or directory already created before a symbolic link to it.

touch hello.txt
Enter fullscreen mode Exit fullscreen mode

3. Navigate to the Desired Location:

cd /learn/file
Enter fullscreen mode Exit fullscreen mode

4. Symlink creation command

ln -s /path/to/original/file_or_directory symlink_name

Example: 

For file

ln -s /learn/file/hello.txt new.txt
Enter fullscreen mode Exit fullscreen mode

It will create a new.txt file in the current directory you are in.

For folder

ln -s /learn/file newFolder
Enter fullscreen mode Exit fullscreen mode

It will create a newFolder folder in the current directory.

5. Verify
Spot the symlink with the linked file or folder.

ls -l
Enter fullscreen mode Exit fullscreen mode

output: 

Folder

lrwxrwxrwx 1 user user 12 Jan 28 13:26 newFolder -> file
Enter fullscreen mode Exit fullscreen mode

File

lrwxrwxrwx 1 user user 14 Jan 28 13:12 new.txt -> learn/hello.txt
Enter fullscreen mode Exit fullscreen mode

6. To delete a symbolic link you can use the rm (remove) command:
Deleting a symbolic link is a straightforward process, and it involves removing the link file itself.

rm symlink_name

Example:

rm new.txt
Enter fullscreen mode Exit fullscreen mode

And that's it! These little shortcuts are perfect for organizing files, creating quick access points, and streamlining your workflow. Experiment, have fun, and enjoy the power of symbolic links! 🚀
Your insights matter! If you spot any errors or have suggestions in my symbolic links guide, drop a comment - let's make it even better together!

Top comments (0)