Linux System Administration for Beginners

Essential Commands

Create and manage soft links

In this lesson, you’ll learn how Linux handles soft links (symbolic links), allowing you to reference files or directories from convenient locations without duplicating data.

When you install an application on Windows, you often get a desktop shortcut pointing to the actual program in C:\Program Files\MyCoolApp\application.exe. Double-clicking the shortcut launches the app even though its files reside elsewhere. A Linux soft link works the same way: it’s a special file containing the path to another file or directory.

The image shows a diagram illustrating a soft link from a Brave browser icon to a file path "C:\Program Files\MyCoolApp\application.exe" with a browser window open in private mode.

Use the ln command with the -s option:

ln -s <path_to_target> <path_to_link>
  • <path_to_target>: the existing file or directory.
  • <path_to_link>: name of the new symlink.

Example:

ln -s /home/aaron/Pictures/family_dog.jpg family_dog_shortcut.jpg

List files in long format to see symlinks marked with an l and showing their targets:

ls -l
# Output:
# lrwxrwxrwx. 1 aaron aaron 28 Jan 14 10:30 family_dog_shortcut.jpg -> /home/aaron/Pictures/family_dog.jpg

To display the stored path directly, use readlink:

readlink family_dog_shortcut.jpg
# /home/aaron/Pictures/family_dog.jpg

Note

Permissions on a symlink itself are always shown as rwxrwxrwx, but access is controlled by the target file’s permissions.

Handling Permissions

If the target file is read-only, attempts to modify it via the symlink will fail:

echo "Test" >> fstab_shortcut
# bash: fstab_shortcut: Permission denied

Absolute paths embed the full directory tree, which can break if you move or rename parent directories:

Warning

Absolute symlinks may become invalid if you relocate or rename directories in the path.
Use relative paths when moving link and target together.

From /home/aaron, create a relative link:

ln -s Pictures/family_dog.jpg relative_dog_shortcut.jpg

This link remains valid as long as you move both the Pictures directory and relative_dog_shortcut.jpg together.

Linking Directories

You can create symlinks to directories—or even across filesystems (unlike hard links):

ln -s /mnt/data/projects my_projects_link
FeatureSymbolic LinkHard Link
Can cross filesystemsYesNo
Links to directoriesYes (with -s)Typically no (restricted by OS)
Indicates broken linkYesNo (hard link always valid until target deleted)
Independent attributesNo (permissions inherited)Shares same inode and attributes

Further Reading

Watch Video

Watch video content

Practice Lab

Practice lab

Previous
Create and manage hard links