AI Hints
Home›Linux Tutorial›Links and Disk Space
Linux · Lesson 40 of 120

Links: Shortcuts to Files

Ln -s.

⏱ 2 min read▶ Video at 50:49🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Sometimes a folder is buried deep, and you visit it all the time. Typing the long path again and again is annoying. Linux lets you make a shortcut, called a symbolic link.

Links: Shortcuts to Files
From the video: Links: Shortcuts to Files
  • A folder buried deep
  • Typing the long path again?
  • Make a shortcut instead

LN dash S makes a symbolic link. First the real target, then the name of the shortcut. Here, a shortcut called site, pointing at projects slash website. LS dash L shows the link, with an arrow, pointing to where it leads. And the first letter is L, for link.

Terminal
ln -s projects/website site
ls -l site
lrwxrwxrwx 1 sam sam 16 Jan  5 09:00 site -> projects/website

You can use the link just like the real folder. LS site lists the website files. CD site takes you there. It's just a pointer. The files only exist once, in the real folder.

Terminal
ls site
css  index.html
cd site
ls
css  index.html

If you delete or move the real folder, the link still exists, but it points to nothing. That's called a broken link, and using it gives, no such file or directory. Deleting a link with RM only removes the shortcut, never the real files. Linux itself uses links everywhere, for example, to point slash bin into slash user slash bin.

keyvalue
Target movedthe link breaks
rm linkremoves only the shortcut
Real filesstay safe
Linux uses theme.g. /bin -> usr/bin

Summary

LN dash S makes a shortcut to a file or folder. Removing the link never touches the real files. Next, checking how much disk space things use.

Key takeaways
  • ln -s target name
  • ls -l shows the arrow
  • rm only removes the link
Next up: Disk Space: du and df — what is using my disk?