Allgemein

ln Cheatsheet

ln Cheatsheet

Basic Syntax

Core ln command forms.

Command Description
ln TARGET LINK_NAME Create a hard link
ln -s TARGET LINK_NAME Create a symbolic (soft) link
ln -sf TARGET LINK_NAME Create or overwrite a symbolic link
ln TARGET... DIRECTORY Create hard links to multiple targets in a directory
ln -s TARGET... DIRECTORY Create symbolic links to multiple targets in a directory

Symbolic Links

Create and manage soft links that point to a path.

Command Description
ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/app Enable an Nginx virtual host
ln -s /usr/bin/python3 /usr/local/bin/python Create a python alias
ln -s /opt/myapp /usr/local/bin/myapp Link a binary into PATH
ln -s TARGET . Create a symlink to TARGET in the current directory
ln -sf NEW_TARGET LINK_NAME Update an existing symlink to point to a new target

Hard Links

Create additional directory entries pointing to the same inode.

Command Description
ln source.txt hardlink.txt Create a hard link to a file
ln file1.txt file2.txt /backup/ Create hard links to multiple files in a directory
ln -v source.txt link.txt Show each link as it is created

Hard links share the same inode and data. Removing one does not delete the data until all hard links are removed. Hard links cannot span filesystems and cannot be created for directories.

Link Options

Flags for controlling overwrite, backup, and verbosity behavior.

Option Description
-s, --symbolic Create a symbolic link instead of a hard link
-f, --force Remove the destination file if it exists before linking
-b, --backup Make a backup of each existing destination file
-i, --interactive Prompt before removing an existing destination file
-n, --no-dereference Treat a symlink to a directory as a normal file
-v, --verbose Print the name of each linked file
-r, --relative Create symbolic links relative to the link location

Inspect and Verify Links

Check where links point and confirm they are valid.

Command Description
ls -l link_name Show the link and its target
ls -la /path/ List all entries including hidden symlinks
readlink link_name Print the target of a symbolic link
readlink -f link_name Print the fully resolved absolute path
stat link_name Show full metadata including inode and link count
file link_name Identify whether a path is a symbolic link
find . -type l Find all symbolic links under the current directory
find . -xtype l Find broken symbolic links

Troubleshooting

Quick checks for common ln issues.

Issue Check
File exists Use -f to force overwrite, or -i to confirm before replacing
Too many levels of symbolic links A circular symlink chain exists; use readlink -f to trace the path
Invalid cross-device link Hard links cannot span different filesystems; use a symbolic link instead
Broken symlink (dangling) The target path no longer exists; update with ln -sf NEW_TARGET LINK_NAME
Symlink points to wrong target Run readlink link_name to confirm the current target, then use ln -sf to correct it

Related Guides

Use these guides for full workflows and file management patterns.

Guide Description
ln Command in Linux Full ln tutorial with examples
How to Remove Symbolic Links in Linux Delete symlinks safely
unlink Command in Linux Remove a single link entry
ls Command in Linux List and inspect files and links
chmod Command in Linux Set permissions on files and links