Linux Professional Institute LPIC-1 Exam 101

Devices Linux Filesystems Filesystem Hierarchy Standard

Create and Change Soft Links

Symbolic links (or “soft links”) are pointers to files or directories, akin to Windows shortcuts. Unlike hard links, which reference the same inode on disk, a symlink stores the path to its target. When you access a symlink, the operating system follows that path and opens the real file or folder.

Link TypeDefinitionUse CaseLimitation
Hard LinkDirect reference to the same inodeDuplicate names for the same dataCannot span filesystems
Symbolic LinkSpecial file containing target’s pathnameFlexible alias or shortcutBroken if the target path changes

Use the ln utility with the -s (or --symbolic) flag:

ln -s <path_to_target> <path_to_link>
# Example: create a shortcut to an image
ln -s /home/aaron/Pictures/family_dog.jpg family_dog_shortcut.jpg
  • <path_to_target>: File or directory you want to reference.
  • <path_to_link>: Name (and optional path) for the symlink.

Note

You can use absolute or relative paths. Relative links remain valid if you move the containing directory, as long as the relative structure doesn’t change.

List files with detailed info:

ls -l family_dog_shortcut.jpg

Output:

lrwxrwxrwx 1 aaron aaron 33 Apr  5 10:00 family_dog_shortcut.jpg -> /home/aaron/Pictures/family_dog.jpg
  • Leading l denotes a symlink.
  • Arrow (->) shows the target path.

To print only the target path without truncation:

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

3. Permissions and Access

Symbolic links always display full permissions (rwxrwxrwx), but actual access is governed by the target’s permissions:

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

Warning

Even though the symlink appears writable, you’re blocked because the real file (/etc/fstab) isn’t writable by your user.

4. Absolute vs. Relative Paths

Absolute paths may break if you rename or move parent directories:

# Create with absolute path
ln -s /home/aaron/Pictures/family_dog.jpg abs_shortcut
# Rename /home/aaron to /home/alex
mv /home/aaron /home/alex
ls -l abs_shortcut
# abs_shortcut -> /home/aaron/Pictures/family_dog.jpg  # Broken link

Better: use a relative link from the same directory:

cd /home/aaron
ln -s Pictures/family_dog.jpg rel_shortcut
ls -l rel_shortcut
# rel_shortcut -> Pictures/family_dog.jpg

This link stays valid under /home/alex as long as the relative tree is preserved.

5. Linking Directories & Cross-Filesystem

Since symlinks store paths, you can reference directories and even across different filesystems:

ln -s /var/log logs_shortcut
ls -l logs_shortcut
# logs_shortcut -> /var/log

The image is a diagram explaining soft links, showing how they can link to files and folders, including across different filesystems.

Further Reading

Watch Video

Watch video content

Previous
Create and Change Hard Links