Linux on call · Chapter 11 of 30
Links
By the end of this chapter you can give one file two names, make a name that leads to another file or folder, and find the links that lead nowhere. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Files and text
- 4 tasks
- Linux
- In the all labs plan
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.
Why you need this
Kabir's deploy plan is simple: every release goes into its own folder under releases, and current leads to the one that is live, so going to a new release or back to the old one is a single command. Today v1.6 is ready. He also wants backup/tapri.conf to always be the very same file as config/tapri.conf, and the shortcuts folder has a link that points at a release deleted long ago.
Bunty set up current by copying v1.5: file current says current: directory, and current/VERSION says 1.5. A copy goes stale the moment a new release lands, and a copied config drifts the first time someone edits the real one. What Kabir wants is not a copy but a link.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Make current a symbolic link to releases/v1.6
Make current a link to the new release, not a copy.
1. Run file current. It is a real folder, a copy of v1.5.
2. Delete the folder current. A link cannot use the name while the folder is there.
3. Make a symbolic link named current that leads to releases/v1.6. Use ln -s. Run it in the chapter folder.
4. Run cat current/VERSION. It should say 1.6.
To pass: current, in the chapter folder, is a symbolic link that leads to releases/v1.6. releases/v1.6 is still a real folder: do not move, copy or rename it.
- Task 2
Make backup/tapri.conf a hard link to config/tapri.conf
Give config/tapri.conf a second name, backup/tapri.conf. Both names are the same file.
1. Use ln with no -s. Give it config/tapri.conf first, then backup/tapri.conf.
2. Run stat on both names. Compare their inode numbers.
To pass: backup/tapri.conf is a hard link to config/tapri.conf: the same inode, not a copy and not a symbolic link. config/tapri.conf stays as it is.
- Task 3
Delete the broken link in shortcuts
One symbolic link in shortcuts leads to a file that was deleted. Delete only that link.
1. Run ls -l shortcuts to see the links.
2. Use find with -xtype l on shortcuts. It lists the links that lead nowhere.
3. Delete the one link it lists, with rm.
To pass: shortcuts has no broken links. It still has its two working links, config and releases, as links, and nothing else.
- Task 4 · interview question
Interview: delete the original under a hard link and a symbolic link
Interview question: what happens to each kind of link when you delete the original file?
1. Go into demo. While original.txt still exists, make hard.txt a hard link to it, with ln (no -s).
2. Still before you delete anything, make soft.txt a symbolic link to original.txt, with ln -s.
3. Only after both links are made, delete original.txt. Then open hard.txt and soft.txt with cat.
4. In links.txt, in the chapter folder (not in demo), write in your own words: does the hard link still work, does the symbolic (soft) link still work, and why.
To pass: demo has hard.txt (a hard link made with ln, in the chapter folder or in demo, and the command worked) and soft.txt (a symbolic link to original.txt), and no original.txt. Order matters: make both links first, then delete original.txt. If you delete it too early, run lab reset to start the chapter again. links.txt names both kinds of link and says what happened to each.
What you will learn
- Inodes: a file's data and its name are two different things.
- ln (hard links): a second name for the same data.
- ln -s (symbolic links): a small file that holds a path, followed whenever it is opened; it works for folders too.
- find -xtype l: list the symbolic links whose path leads nowhere.
More in Files and text
Build "Links" yourself
Tapri’s ordering app moves onto a Linux server, and the server is now yours to run. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Linux on call are free. This one comes with the all labs plan.