Links and finding files (ln, find, which)
You see the difference between hard and symbolic links through inodes and link counts, try what happens when the original is deleted, find broken links, use find by name, type, size, time and owner, act on the results with -exec and -delete, reach a command’s real file with which, type, whereis and readlink; at the end you fix a link pointing to the wrong version, clean old temporary files and find the file that has three names. The values differ in every lab.
Level 101 · 50 min
On the application server there is a shortcut called /srv/app/current, and the web server runs from there. Daniel is suspicious: "We installed the new version yesterday but the site still looks old. And the disk is filling up; find out what takes the space."
A symbolic link (symlink) is a small note with a path on it: "the real file is over there". If the real file is deleted the note becomes useless (a broken link). A hard link is a second name given to the same file, that is the same inode; the file lives until all its names are deleted. The figure compares the two.
find is Linux’s most powerful search tool: it walks a folder tree, finds every file matching its conditions and, if you want, runs a command on each one.
What you will do in this lesson
- A hard link: a second name for the same file
- Read a symbolic link: readlink
- When the original is deleted
- Find broken links: find -xtype l
- Who fills the disk? find -size and -exec
- Whose files? find -user, -mtime
- A command’s real file
- Point to the right version
- Clean the old temporary files
- The file with three names
- Short quiz
Skills you will earn
- Understanding hard links and link counts
- Reading inode numbers (ls -i, stat)
- Reading and fixing symbolic links (readlink, ln -sfn)
- Finding broken and multi-link files (-xtype, -links)
- Searching by size with find and running -exec
- Finding odd files by owner and permission (find -user, -perm)
- Asking what a command is (type, which -a)
- Deleting safely with find (-mtime, -delete)
← Creating, copying, moving, deleting and wildcards · Linux fundamentals · Reading contents: cat, less, head, tail -f →
Start for free