Symbolic links are an essential feature in Unix and Linux systems, offering powerful ways to manage files and directories.
They allow you to create references to files or directories without duplicating their content. This can help reduce disk usage, simplify directory structures, and make system management more efficient.
If you’re interested in practical command-line tricks, you might also enjoy this related article: Grep Trick for ps. It covers a simple but clever way to improve your process searches using ps and grep.
For developers, system administrators, or anyone working with large codebases or configuration environments, symbolic links offer flexibility in linking resources from one location to another. They are especially useful in scripting, version management, and deployment scenarios.
This is another symbolic link article. I have previously written a short article on how to create symlink and hard links. To read other Unix and Linux link-related articles, check the archive.
Symbolic Link:
Symbolic links indicate file paths (names). The paths can be both relative (e.g., my/dir) and absolute (e.g., /my/dir). When modifying, editing, or removing the target file, the symbolic link remains unchanged. However, if the target file is deleted or moved, the symbolic link becomes broken and will not function until it is corrected or recreated.
To create a symbolic link, use:
ln -s /path/to/file linkname
If you use relative paths when creating symlinks and later move the entire directory structure, the symlink will not break, since the relative path remains valid within the new location.
Some operations on symlinks act on the target file. For example, editing the symlink or changing its permissions will affect the file it points to. On the other hand, operations like renaming, moving, or deleting a symlink will only affect the symlink itself, not the target file.
Example with permissions:
ls -l link
lrwxrwxrwx 1 geekvater geekvater 6 2012-07-27 12:21 link -> myfile
chmod 444 link
ls -l link
lrwxrwxrwx 1 geekvater geekvater 6 2012-07-27 12:21 link -> myfile
ls -l myfile
-r--r--r-- 1 geekvater geekvater 0 2012-07-27 12:21 myfile
The permission change applied to the symlink actually affected the target file (myfile), not the symlink itself.
Symlink size:
The size of a symlink is equal in bytes to the number of characters in the name of the target file.
Example:
touch myfile
ln -s myfile link
ls -l link
lrwxrwxrwx 1 geekvater geekvater 6 2012-07-27 12:21 link -> myfile
Since “myfile” has 6 characters, the symlink’s size is 6 bytes.
How to find all symbolic links pointing to a file:
You can use the find command:
find -L . -xtype l -samefile myfile
Example:
ln -s myfile link
ln -s myfile link2
ln -s myfile link3
find -L . -xtype l -samefile myfile
./link3
./link2
./link
This command searches for symbolic links (-xtype l) that point to the same file as “myfile”, following symlinks using the -L option.
Symbolic Link versus Windows Shortcut:
There is a significant difference between symbolic links and Windows shortcuts. A symbolic link acts like a real file path at the filesystem level. Windows shortcuts, with the .lnk extension, contain metadata and can only be interpreted properly by the GUI or shell. They cannot replace executables or be used as full system-level references like Unix symlinks can.
In Linux, symlinks can be used transparently by command-line tools and scripts. In contrast, a .lnk file on Windows is not executable or usable in command-line environments in the same way. This difference becomes particularly important when building cross-platform applications or deploying scripts across environments.
Additional Notes:
To inspect a symlink’s target:
readlink link
To resolve the full path of a symlink:
readlink -f link
To remove broken symlinks:
find -L . -type l -delete
Regular auditing of symlinks is a good practice, especially in environments where files are frequently moved or updated. Keeping your symlinks clean and functional helps avoid runtime errors and unexpected behaviors.
Conclusion:
Symbolic links are more than just shortcuts—they are integral to Unix-like system design. They offer elegant solutions to real problems like reducing redundancy and creating dynamic references across the file system.
As geekvater continues exploring Linux concepts and practical tools, understanding how and when to use symbolic links is a skill worth mastering. From basic file referencing to advanced system configuration, symlinks can dramatically simplify your workflow and improve your system’s efficiency.
Whether you’re managing dotfiles, configuration folders, or codebases shared across environments, symlinks give you powerful tools to keep your systems organized, lean, and maintainable.






Pingback: FOSS News Round-Up #1 - 99XP
Pingback: How to Find Your Computer Hardware Information on Linux - iDoLinux
The command to remove broken symlinks is:
find -L . -type l -delete
not, as you have it:
find -L . -xtype l -delete
which deletes ALL symlinks.
fixed, thank you for the feedback.
Pingback: How to Find Your Computer Hardware Information on Linux - Open Source Software News
Pingback: The Linux and Unix Basename and Dirname Commands with Examples - iDoLinux
Pingback: Understanding Symbolic and Hard Links in Linux and Unix - iDoLinux
Pingback: Count How Many Times a String Appears in a File with a One-Liner - iDoLinux
Pingback: Count How Many Times a String Appears in a File with a One-Liner - Open Source Software News