Module 1 · Lesson 3 of 28

Filesystem: tree, paths, inodes, links

Learn the filesystem tree, paths, inodes, hard and symbolic links, and glob patterns, from the FHS down to deleted-but-open files.

  • Beginner to advanced
  • 22 min read
  • 30 min lab
What you will need

Ubuntu 24.04 (WSL2, VM or container)

By the end you can 6 objectives
  • Describe the single filesystem tree and state what /etc, /var, /home, /usr, /dev, /proc, /sys and /tmp hold.
  • Navigate with absolute and relative paths and the dot and tilde shortcuts, and predict what cd .. does at the root.
  • Read the inode number and link count with stat and ls -i, and explain why a filename is separate from its data.
  • Create a hard link and a symbolic link and predict what survives when the original name is deleted.
  • Select files with glob patterns and tell globbing apart from brace expansion and regular expressions.
  • Explain why a deleted file can still occupy disk space and diagnose the df-versus-du mismatch.
Read the lesson below; the video will appear here when published.
01

One tree, rooted at /

3 min read

On Windows you deal with separate drive letters, and a file name starts with something like C:. Linux has one tree. Your own files, the installed programs, the devices, and even the kernel's running view of the machine all hang off a single . If you can read that tree, you can find and fix almost anything on the system.

The follows a standard layout at its top level called the Filesystem Hierarchy Standard, or FHS. Each top-level directory has a job. /etc holds system-wide configuration. /home holds each user's personal files. /var holds changing data such as logs and caches. /usr holds installed programs and libraries. /dev holds device files, the way the system talks to hardware. /tmp holds temporary files that may be cleared on reboot. /run holds runtime state created since boot, and /sbin holds system-administration programs that often need root.

On a modern distribution you may notice /bin and /sbin are just symbolic links to /usr/bin and /usr/sbin. This merged-usr layout concentrates the programs in one place, while the separate names remain for backwards compatibility. A few more top-level directories complete the picture: /mnt is for filesystems an administrator mounts temporarily by hand and /media is where removable media such as USB sticks are mounted automatically, /root is the root user's home directory, /opt holds self-contained third-party software, and /srv holds data served to others such as a website.

Two directories are special: /proc and /sys. They are s. The kernel synthesises their contents while the system runs, so they live in memory and disappear at shutdown. That is why they report a size of zero even though they are full of entries:

bash
ls -ld /proc /sys

Typical output (yours will differ) shows dr-xr-xr-x and a size of 0 for both. The size is 0 not because the directory is empty, but because nothing in it is stored on disk. It is kernel state, rebuilt every boot. /proc exposes one directory per running process plus system statistics; /sys exposes devices and kernel objects. Both are how administrators and tools read live kernel state through ordinary file operations.

A minimal embedded rootfs is the same idea, smaller

A BusyBox-based board still needs the same core directories: /bin, /etc, /dev, /proc, /sys and /tmp. It often omits /home and merges /usr into /bin to save space, and it mounts /proc and /sys early in init scripts because tools rely on them. The mental model carries over unchanged.

The filesystem tree/rootetcconfigurationhomeuser filesvarlogs, cachesusrprograms, librariesdevdevice filestmptemporary filesprocvirtual kernel statesysvirtual devices/rootetcconfigurationhomeuser filesvarlogs, cachesusrprograms, librariesdevdevice filestmptemporary filesprocvirtual kernel statesysvirtual devices
The single filesystem tree rooted at / with the FHS directories hanging off it: etc for configuration, home for user files, var for logs, usr for programs, dev for devices, tmp for temporary files, and the virtual proc and sys.
02

Paths and navigation

3 min read

To use the tree you have to name a location, and there are two ways. A is either absolute or relative. An absolute path starts at the root and names the full route, such as /home/learner/notes. A relative path starts from where you are right now, shown by pwd (print working directory). If you are in /home/learner, then notes means /home/learner/notes. Absolute paths always mean the same thing no matter where you run them; relative paths depend on your current directory.

Three shortcuts save typing. . means this directory. .. means the parent. ~ means your home directory. So cd .. goes up one level, cd ~ goes home, and ls . lists the current directory explicitly. You can chain them: cd ../.. goes up two levels, and ~/notes is your home's notes directory.

bash
pwd
cd /tmp
pwd
cd ..
pwd
cd ~
pwd

The first cd uses an absolute path (it starts with /), so it works from anywhere. The second moves up one level, relative to wherever you now are.

An edge case worth knowing: the root has no parent. From /, running cd .. simply stays at /. It does not error and it cannot go higher, because there is nothing above the root. The kernel treats .. at the root as / again, which keeps the tree consistent everywhere.

Three more conventions round out navigation. A trailing slash is usually harmless: /tmp/ and /tmp name the same directory. cd - jumps back to your previous directory, which is handy when toggling between two places. And to run a program that sits in your current directory you must prefix it with ./, because the shell does not search . in the PATH; ./script is an explicit relative path, while script alone would be looked up in the PATH directories.

From /home/learner the relative path notes resolves to /home/learner/notes; an absolute path such as /tmp resolves the same from anywhere, and .. from / stays at /.

  • cwd: /home/learner
  • value: notes
Absolute vs relative paths/starthomelearnernotes/starthomelearnernotes
How an absolute path such as /home/learner/notes is resolved from the root, versus a relative path such as notes resolved from the current working directory.
Absolute and relative paths, and cd .. at the root
learner@embeddex:~/lab$ # Where am I now?
learner@embeddex:~/lab$ pwd
/home/learner/lab
learner@embeddex:~/lab$ # Move with an absolute path
learner@embeddex:~/lab$ cd /tmp
learner@embeddex:/tmp$ pwd
/tmp
learner@embeddex:/tmp$ # One level up: /tmp's parent is /
learner@embeddex:/tmp$ cd ..
learner@embeddex:/$ pwd
/
learner@embeddex:/$ # The root has no parent, so this stays at /
learner@embeddex:/$ cd ..
learner@embeddex:/$ pwd
/
learner@embeddex:/$ # Tilde always goes home
learner@embeddex:/$ cd ~
learner@embeddex:~/lab$ pwd
/home/learner/lab
03

A file is a name and an inode

3 min read

Here is the mental model that makes the rest of this session click: a file is two separate things. The data lives in a numbered record called an . The name is just an entry in a directory that points to that inode. The inode holds the size, permissions, ownership, three timestamps, and a — how many names point at it. Notice what is missing: the inode does not store the filename. The name lives only in the directory entry.

stat shows this. Run it on a file and read the Links line, which is the count of names pointing at that inode, and the Inode line, which is its number:

bash
echo hello > a.txt
stat a.txt
ls -i a.txt

Typical stat output (yours will differ) includes Size: 6, Links: 1, and an Inode: number. ls -i prints that same inode number as the first column. A fresh file has a link count of 1: exactly one name points at it.

The important idea is that the name and the data are separate. A directory is not a box that contains files; it is a table of name to inode. This separation is exactly what makes links possible, which is the next two sections.

ls -li shows all of this in one line: inode number, permissions, link count, owner, group, size, date and name. Directories also have link counts, and they start higher than 1: a fresh directory has at least 2, because its own name in the parent plus its internal . entry both point at it, and each subdirectory adds one more through its .. entry. That is why a directory's link count grows as you add subdirectories, while a regular file's link count only grows when you hard-link it.

Name, inode, dataa.txtdirectoryentryinodesize, mode,timesdata blocksa.txtdirectoryentryinodesize, mode,timesdata blocks
A directory entry holding a name that points to a numbered inode, which in turn holds the data blocks, size, permissions, timestamps and link count.
stat and ls -i reveal the inode behind the name
learner@embeddex:~/lab$ echo hello > a.txt
learner@embeddex:~/lab$ # Note Links: 1 and the Inode number
learner@embeddex:~/lab$ stat a.txt
  File: a.txt
  Size: 6               Blocks: 8          IO Block: 4096   regular file
Device: 8,48    Inode: 72241       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   learner)   Gid: ( 1000/   learner)
Access: 2026-11-15 05:45:18.070069357 +0200
Modify: 2026-11-15 05:45:18.070069357 +0200
Change: 2026-11-15 05:45:18.070069357 +0200
 Birth: 2026-11-15 05:45:18.070069357 +0200
learner@embeddex:~/lab$ # The same inode number appears as the first column
learner@embeddex:~/lab$ ls -i a.txt
72241 a.txt
learner@embeddex:~/lab$ # Inode, permissions, link count, owner, size and name in one line
learner@embeddex:~/lab$ ls -li a.txt
72241 -rw-r--r-- 1 learner learner 6 Nov 15 05:45 a.txt
04

Hard links

3 min read

Because a name is separate from the data, you can give one inode several names. ln creates a . Both names point at the same data, and the link count rises to 2. Delete one name and the data survives, because the other name still points at it. Neither name is the original; they are two equal labels for one file.

1create the link

bash
echo important > orig.txt
ln orig.txt hard.txt
ls -li orig.txt hard.txt

Both lines show the same inode number, and the link count (the second column of ls -l) is now 2.

2delete one name and watch

bash
rm orig.txt
cat hard.txt
stat hard.txt

cat hard.txt still prints the data, and stat now reports Links: 1. Removing one name only lowered the count; the data lives until the last name is gone.

Hard links have two hard limits. They cannot cross filesystems, because an inode number is only meaningful within its own filesystem. And hard links to directories are normally forbidden, because they could create cycles in the tree that would break traversal. In both cases the system refuses with an error, and a symbolic link is the right tool instead.

Hard links have limits

Trying to hard-link across filesystems fails with Invalid cross-device link, and linking to a directory fails with hard link not allowed for directory. Reach for ln -s in both cases.

To find every name for one file, search by inode number: find . -inum <number> lists all hard links to it. Note the difference from copying. cp reads the data and writes a fresh inode, so the copy is independent, while ln shares the inode, so editing one name changes what the other name sees. Hard links are used deliberately to deduplicate identical files, and by backup tools such as rsync --link-dest that keep unchanged files as hard links to save space.

Two names, one inodeorig.txtname 1inodelinks = 2hard.txtname 2data blocksorig.txtname 1inodelinks = 2hard.txtname 2data blocks
Two directory entries, orig.txt and hard.txt, both pointing at the same inode, with the link count raised to 2.
A hard link adds a second name to the same inode
learner@embeddex:~/lab$ # one file, one name
learner@embeddex:~/lab$ echo important > orig.txt
learner@embeddex:~/lab$ ls -li orig.txt
72241 -rw-r--r-- 1 learner learner 10 Nov 15 05:45 orig.txt
learner@embeddex:~/lab$ ln orig.txt hard.txt
learner@embeddex:~/lab$ # same inode number, link count is now 2
learner@embeddex:~/lab$ ls -li orig.txt hard.txt
72241 -rw-r--r-- 2 learner learner 10 Nov 15 05:45 hard.txt
72241 -rw-r--r-- 2 learner learner 10 Nov 15 05:45 orig.txt
learner@embeddex:~/lab$ rm orig.txt
learner@embeddex:~/lab$ # the data survives through the other name
learner@embeddex:~/lab$ cat hard.txt
important
learner@embeddex:~/lab$ stat -c 'links=%h inode=%i name=%n' hard.txt
links=1 inode=72241 name=hard.txt
05

Symbolic links

3 min read

ln -s creates a , usually called a symlink. Unlike a hard link, it has its own inode and its own data — the data is just a path string. ls -l shows the link with an arrow, and readlink prints the stored path:

bash
echo important > orig.txt
ln -s orig.txt soft.txt
ls -l soft.txt
readlink soft.txt

The ls -l line reads soft.txt -> orig.txt. A symlink does not change the target's link count, because it does not point at the inode — it points at a name.

Because a symlink stores a path, not a reference to an inode, it can break. Delete the target and the link is left dangling: it points at a name that no longer exists, and reading it fails with No such file or directory.

bash
rm orig.txt
cat soft.txt

The target of a symlink can be relative or absolute, and this matters. A relative target such as orig.txt is resolved starting from the directory that contains the link, not from your current directory. An absolute target such as /home/learner/orig.txt always means the same thing. This is why moving a link and its relative target together keeps working, while moving only one of them breaks the link.

readlink -f resolves a symlink all the way to a final real path, following every link in the chain, and it fails if the target is missing. A symlink can also point at itself, directly or in a circle; the kernel caps the number of links it follows and then fails with Too many levels of symbolic links, which is the tell-tale sign of a link loop.

soft.txt stores the relative path orig.txt, so it resolves from the link's own directory to /home/learner/orig.txt, not from the current working directory /tmp.

  • cwd: /tmp
  • value: /home/learner/soft.txt
A symlink stores a pathsoft.txtsymlinkinodepath:orig.txtorig.txttarget nameinodelinks = 1Exit from step 3: target deleteddangling linkdata blockssoft.txtsymlinkinodepath:orig.txtorig.txttarget nameinodelinks = 1Exit from step 3: targetdeleteddangling linkdata blocks
A symlink as a small file with its own inode that stores a path to the target name; when the target is deleted the link dangles and reads fail.
A symlink stores a path and dangles when its target is gone
learner@embeddex:~/lab$ echo important > orig.txt
learner@embeddex:~/lab$ ln -s orig.txt soft.txt
learner@embeddex:~/lab$ # The arrow shows soft.txt -> orig.txt
learner@embeddex:~/lab$ ls -l soft.txt
lrwxrwxrwx 1 learner learner 8 Nov 15 05:45 soft.txt -> orig.txt
learner@embeddex:~/lab$ # The stored path string
learner@embeddex:~/lab$ readlink soft.txt
orig.txt
learner@embeddex:~/lab$ # Delete the target
learner@embeddex:~/lab$ rm orig.txt
learner@embeddex:~/lab$ # A dangling symlink fails to read
learner@embeddex:~/lab$ cat soft.txt
cat: soft.txt: No such file or directory
06

Inside the inode and the directory entry

4 min read

Now look under the hood. A is tiny: a name and an inode number, and nothing else. The inode is where everything about the file lives: the file type and permissions (the mode), the owning user and group, the size in bytes, three timestamps, the link count, and a set of pointers to the data blocks.

The three timestamps trip people up. atime is the last access time, mtime the last modification of the file's contents, and ctime the last change to the inode itself, such as a rename, a chmod, or a hard-link creation. ctime is change time, not creation time. Creation (birth) time is a separate, newer field: ext4, XFS and Btrfs store it, and since coreutils 8.31 stat shows it on the Birth: line through the statx() system call (older tools and some filesystems show -). A rename changes ctime but not mtime, because the data did not change.

Step by stepHow the kernel resolves a path
  1. Start at the root or the working directory: the kernel begins at / for an absolute path, or at the process's working directory for a relative one.

  2. Read the next component: it looks up the next name, such as home, in the current directory's entries.

  3. Follow the inode: the matched entry gives an inode number, and the kernel reads that inode to learn whether it is a directory.

  4. Descend and repeat: if it is a directory, the kernel moves into it and repeats from step 2 for the next component.

  5. Resolve links and the last component: a symlink redirects to its stored target; the final component yields the inode the name was after.

This walk is cached in memory as dentries (directory-entry cache objects), which is why repeating a path is fast even though the on-disk lookups are many small reads.

Going deeperWhat an ext4 inode and directory entry actually look like

On ext4, an inode is a fixed-size structure per file. Its fields include i_mode (file type and permissions), i_uid and i_gid (ownership), i_size (logical size), i_links_count (link count), i_atime, i_mtime, i_ctime, and a 60-byte area that says where the data lives. On ext2 and ext3 that area is an array of block pointers: 12 direct pointers, then one single-, one double- and one triple-indirect pointer, which is how a fixed-size inode can describe a very large file. ext4 normally uses the same 60 bytes for an extent tree instead: each extent says "these N consecutive blocks start at block B", so a large contiguous file needs a handful of extents rather than thousands of pointers (filefrag -v file shows them; ext4 still reads the old indirect format for compatibility). A directory is itself a file whose blocks hold entries of the form:

c
struct ext4_dir_entry_2 {
    __le32 inode;          /* inode number this name points at */
    __le16 rec_len;        /* length of this entry */
    __u8  name_len;        /* length of the name */
    __u8  file_type;       /* regular file, dir, symlink, ... */
    char  name[];          /* the name, not null-terminated */
};

Notice the inode field is just a number and the name sits next to it. This is the literal realisation of "a directory is a table of name to inode", and it is why a filename can be at most 255 bytes on ext4 while the inode knows nothing about the name.

Inside the inodemodefile type +permissionsuid / gidowner / groupsizebytesatime /mtime /ctimeaccess, modify,changelink countnames pointinghereblockpointersdirect +indirectthe filename is not stored in theinode; it lives in the directoryentry
The fields inside an inode — mode, uid, gid, size, atime, mtime, ctime, link count and block pointers — beside a directory entry holding only a name and an inode number.
07

Globbing and the shell

3 min read

The shell can expand patterns before it runs a command, which is how you select many files at once. A is expanded by the shell itself, not by the program you run. ls *.txt never sees the asterisk: the shell replaces the pattern with every matching filename first. * matches any number of characters, ? matches exactly one, and [...] matches one of the listed characters or a range such as [a-c].

The classic mistake is thinking ? means one or more. It means exactly one. So f?.txt matches f1.txt but not f10.txt (two characters) or f.txt (zero).

bash
ls f?.txt
mkdir txt log png bak
mv *.txt txt/
mv *.log log/

{a,b} is different. It is brace expansion, which happens even when no files match, and it is not really a wildcard: {txt,log} expands to the two words txt log regardless of what is on disk. Two more subtleties matter. * does not match a leading dot, so hidden files such as .bashrc need .* or .[!.]* explicitly. And if a pattern matches nothing, the shell by default passes the literal pattern to the program, which is why a typo can produce a confusing "No such file or directory" naming the pattern itself.

Going deeperGlobbing is not a regular expression

People who know regex often reach for * and . the way regex uses them, and it breaks. In a glob, * means any characters, not "zero or more of the previous thing", and . is a literal dot, not "any character". So *.txt means "anything ending in .txt", while the equivalent regex would be .*\.txt. A glob also matches whole names, while a regex can match part of a line. grep takes a regex; the shell's filename expansion is a glob. Keep the two syntaxes separate.

Bash gives you control over the edge cases. With shopt -s nullglob, a pattern that matches nothing expands to nothing at all instead of the literal pattern, which removes a whole class of surprising errors in loops. With shopt -s failglob, the shell reports an error instead. With shopt -s extglob, you get richer patterns such as @(a|b) for one of several and +(x) for one or more, though these stray beyond the portable basics.

Glob patternsWhat itmatchesExample*anycharacters*.txt matchesa.txt?exactly onecharacterf?.txtmatchesf1.txt[12]one listedcharacter[12].txtmatches 1.txt{a,b}eachalternativebraceexpansion,not awildcard
The glob characters * ? [12] and the brace expansion {a,b}, each matched against example filenames to show which names each selects.
The shell expands globs before the command runs
f2.txt
learner@embeddex:~/lab$ # * matches any run, including zero: f.txt is back too
learner@embeddex:~/lab$ ls f*.txt
f.txt
f1.txt
f10.txt
f2.txt
learner@embeddex:~/lab$ mkdir txt log
learner@embeddex:~/lab$ # The shell expands *.txt before mv ever runs
learner@embeddex:~/lab$ mv *.txt txt/
learner@embeddex:~/lab$ mv *.log log/
learner@embeddex:~/lab$ ls txt log
log:
app.log

txt:
f.txt
f1.txt
f10.txt
f2.txt
learner@embeddex:~/lab$ # Brace expansion works even when no file matches
learner@embeddex:~/lab$ echo {txt,log}
txt log
08

Deleted but still open

3 min read

rm does not destroy a file; it calls the system call, which removes one name and decrements the link count. The data is freed only when two things are both true: the link count has reached zero, and no process has the file open. If a process still holds a , the kernel keeps the inode and its blocks alive until the last descriptor closes. This is why df can report a disk full while du finds nothing large: a deleted file is still held open, invisible to directory listings but still using blocks.

Two levels are involved, and it is worth keeping them straight. The file descriptor is the small number a program holds; it points to an open file description, which records the file offset and mode; that in turn points to the inode. When a process is forked, the child shares the same open file description, and that is exactly why a deleted log file does not free its space until every process that inherited the descriptor has closed it. Log rotation depends on this: a daemon keeps writing to a renamed and deleted file until it is told to reopen, which is why logrotate sends a signal after rotating.

1hold a file open and delete its name

bash
echo secret > data.bin
exec 3<data.bin
rm data.bin

exec 3<data.bin opens the file on descriptor 3 in the current shell. Deleting the name removes the only directory entry, but the descriptor still refers to the inode.

2see the proof in /proc

bash
ls -l /proc/$$/fd/3

The entry shows descriptor 3 still pointing at data.bin, with the path marked (deleted). The inode is alive even though no directory lists the name.

3read the data back

bash
cat <&3

The data is still there, read through the open descriptor. Close it and the blocks are finally freed.

Step by stepLife of a deleted-but-open file
  1. Named and open: the file has one name and one open descriptor; the link count is 1.

  2. Unlinked: rm removes the name and the link count drops to 0, but the descriptor keeps the inode referenced.

  3. Still allocated: blocks stay allocated, so df still counts them while du no longer sees them.

  4. Visible as (deleted): /proc/<pid>/fd/ shows the descriptor pointing at a path marked (deleted).

  5. Last close frees it: when the final descriptor closes, the inode and its blocks are reclaimed and the space appears.

Deleted but still openNamed and openlinks = 1Unlinked, openlinks = 0Freedblocks reclaimedTransitionsunlink (rm)Named and openlinks = 1Unlinked, openlinks = 0last closeUnlinked, openlinks = 0Freedblocks reclaimedNamed and openlinks = 1Unlinked, openlinks = 0Freedblocks reclaimedTransitionsunlink (rm)Named andopenlinks = 1Unlinked,openlinks = 0last closeUnlinked,openlinks = 0Freedblocksreclaimed
A deleted file whose inode and data blocks are still allocated because a running process holds an open file descriptor, visible under /proc/pid/fd with a (deleted) marker.
Deleted, but still open: the data lives on
learner@embeddex:~/lab$ echo secret > data.bin
learner@embeddex:~/lab$ # open the file on descriptor 3
learner@embeddex:~/lab$ exec 3<data.bin
learner@embeddex:~/lab$ rm data.bin
learner@embeddex:~/lab$ # the kernel still knows the file, marked (deleted)
learner@embeddex:~/lab$ ls -l /proc/$$/fd/3 | sed 's/.*-> //'
/home/learner/lab/data.bin (deleted)
learner@embeddex:~/lab$ cat <&3
secret
09

Common mistakes and how professionals diagnose them

3 min read

These are the mistakes learners hit most, with the symptom, the cause, and the diagnostic that proves it.

  • cat link.txt: No such file or directory. The symlink's target was deleted, so the link dangles. Diagnose with ls -l to see the arrow, then either recreate the target or remove the link.
  • f?.txt did not match f10.txt. ? matches exactly one character and f10 has two. Diagnose by reading the pattern aloud, then use f*.txt, where * matches any number of characters, including none.
  • ln: Invalid cross-device link. A hard link cannot cross filesystems, because inode numbers are local to one filesystem. Diagnose with df on both paths; use ln -s instead.
  • Disk still full after rm. A process still holds the deleted file open. Diagnose with lsof +L1, which lists files with a link count below 1, then restart or close that process.
  • du and df disagree wildly. Either deleted-but-open files (found with lsof +L1) or files hidden underneath a mount point (mounting over a non-empty directory hides its contents from du but not from df).
  • No space left on device while df -h shows free space. The inode table is full. Check df -i.
  • cd .. at / did nothing. The root has no parent; the kernel maps .. at the root to / again. This is expected, not an error.
  • Confused by stat showing Links: 1. It is the count of names pointing at the inode. Hard-link the file and watch it become 2; a symlink does not change it.
Going deeperInode exhaustion on small embedded filesystems

A filesystem can be full in two independent ways: out of data blocks, or out of inodes. Embedded flash filesystems are sized tightly, and a directory full of thousands of tiny files can exhaust the inode table long before the data blocks are used. df -i shows inode usage separately from df's block usage, and a filesystem at 100% inodes refuses to create new files even with gigabytes free. This shows up on real devices as log files that cannot be written or packages that fail to install with No space left on device. On ext4 the inode count is fixed at mkfs time, so the fix is either to remove small files or recreate the filesystem with a larger inode count. Tools like find -printf or a count of directory entries reveal where the inodes went.

Verify before you fix

Before changing anything, confirm the diagnosis with one command: ls -l for a dangling link, lsof +L1 for a deleted-but-open file, and df -i for inode exhaustion. The fix that matches the proven cause is usually small.

Disk-full diagnosisdf full, dusmalllsof +L1deleted-but-open?restartprocessdf -iinodesexhausted?Exit from step 2: no deleted filescheck df -i and mountsremovesmall filesdf full, dusmalllsof +L1deleted-but-open?Exit from step 2: no deletedfilescheck df -i and mountsrestartprocessdf -iinodesexhausted?removesmall files
A diagnostic flow from the symptom of a full disk or a failing link through lsof +L1, df -i and ls -l checks to the correct fix.
10

Try it

1 min read

Open the lab for this session and work through it in a scratch directory. Organise 500 mixed files into four folders using four mv commands, run the hard-link and symlink experiment and record which link still reads after you delete the original, then hold a file open, delete it, and recover the data through /proc/$$/fd/. Each exercise proves one idea from this lesson, and the practice pack's questions and interview prompts cover the same ground. Do the lab before moving on to viewing and editing text.

Key takeaways

  • Linux is one tree rooted at /, and the FHS says where each kind of file lives; /proc and /sys are virtual.
  • An absolute path starts at the root; a relative path starts from the working directory; cd .. at / stays at /.
  • A filename is a directory entry pointing to an inode that holds the data, metadata and link count.
  • A hard link is a second name for the same inode; a symlink stores a path and dangles when its target is deleted.
  • Hard links cannot cross filesystems or point at directories; symlinks can do both.
  • Globbing is done by the shell: * matches any run, ? exactly one character, and {a,b} is brace expansion.
  • Deleting a name only lowers the link count; the data lives until the last open file descriptor closes.

Reflect

  1. Explain to a colleague, in two sentences: describe the single filesystem tree and state what /etc, /var, /home, /usr, /dev, /proc, /sys and /tmp hold.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?

On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

Practise this lessonExercises, quiz, interview preparation and spaced review

References and further reading

Official documentation first. Links checked when the lesson was published.

Find your next step

↑ ↓ to move · Enter to open · Esc to close