ln — links
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
A link is a second name for a file. There are two kinds.
A symbolic link (symlink) is a "shortcut": a small file that holds the path to its target.
ln -s /opt/app/v2.1 current # current → /opt/app/v2.1
ls -l current # lrwxrwxrwx … current -> /opt/app/v2.1
readlink current # /opt/app/v2.1 — where it points
If you delete the target, the symbolic link becomes "broken" (dangling). Links can point to folders and to other drives.
A hard link is one more name of the very same file on the disk:
ln data.txt data_copy.txt # without -s
A file exists as long as it has at least one name. Delete data.txt, and the data stays available through data_copy.txt. Hard links work only for files and only within one drive.
Where you meet them: /usr/bin/python3 → python3.12; switching versions (current → v2.1); web server configs (sites-enabled/ → ../sites-available/).
Task. Create a symbolic link latest to the file v2.txt, print the contents of the file through the link, and then print where the link points (readlink).
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.