Skip to main content
Systems Programming

Linux File System — Inodes, File Types, Permissions and Links

Published: 2026-08-20
Level: postgraduate
Audience: Postgraduate students in Systems Programming

5.1 Inodes and File Identity

Hook — why inodes matter before you ever run ls: Every file tool you will use — ls, cp, rm, find, backup and sync — works with names you type, but the kernel works only with inode numbers. If you do not see that split, rm looks like it deletes data and mv looks like it copies. Once you see the inode card behind the name label, both commands become clear: one removes a label, the other sticks the same label on a new path.

Intuition — identity card and labels: Keep the session's picture: the inode is the identity card that stores type, permissions, owner, group, size, timestamps, link count and block pointers; the name you type in a directory is a sticky label that points to that card. You can peel the label off (rm), copy the label to a second spot (hard link), or write a note that says "go look at that other card" (symbolic link). Peeling or copying a label never changes the card itself. The card changes only when you edit metadata or content. This picture holds for regular files and directories alike — both get an inode from the same number space. Where the picture stops: it does not show that the card also holds the block map that actually locates bytes on disk; that map is what the final arrow in the mapping points to.

In Linux every file system object — whether it appears as a regular file or as a directory — is identified inside the kernel by a unique integer called the inode number. An inode is the on-disk data structure that stores the metadata for one object: its type, permissions, owner, group, size, timestamps, block pointers and link count. The directory entry you see by name is only a pointer that maps a human-readable name to that inode. Two different names can point to the same inode, and deleting a name only removes one pointer until the link count drops to zero.

Think of the inode as the identity card of a file and the name as a label stuck on the card. You can peel off the label and stick a new one on, but the card stays the same. That mental model explains why renaming a file, changing its permissions, or editing its contents does not give it a new identity, unless you create a genuinely new object.

Real-world: every tool that walks the file system — backup software, package managers, indexing services — relies on inode numbers to detect when the same underlying object appears in two places without copying data. Build systems such as make and backup tools such as rsync compare inode numbers and timestamps to avoid copying a file that is already present under a second name.

5.1.1 Mathematical View of the Inode Table

Formalize — name to inode to metadata: The file system keeps two structures that work together. A directory is a table of pairs (name, inode\_number); an inode table is an array indexed by that number. The lecture writes the chain as one mapping:

where is a positive integer, is the set of natural numbers, and the final block pointers locate the physical data on disk. In kernel terms struct stat returns st_ino for the number, st_nlink for the link count, and st_blocks for allocated blocks. The session's wording preserved is: "Inode number is a unique number which will help me identify the file." Uniqueness is per file system; two different mounted file systems can each have inode 3277256.

The session describes the inode number as the first column of a long listing. There is no deep formula here, but it helps to see the relation as a mapping.

The file system maintains a table where

where is a positive integer, is the set of natural numbers, and the final block pointers locate the physical data on disk. The verbal description preserved from the session is: "Inode number is a unique number which will help me identify the file."

5.1.2 Displaying Inode Numbers — ls -i and ls -li

Two small options control what ls shows:

  • ls -i — show only the inode number and the name.
  • ls -li or equivalently ls -i -l — show the long listing with the inode number as the added first column.
  • ls -l alone — long listing without inode numbers.

The i stands for inode — the first letter of the word. A common moment of confusion in the session was to read i as something else; the correction is that i always means inode in this context.

A typical ls -li line looks like (values are examples):

3277256 -rw-rw-r-- 1 owner group 0 May 20 12:00 paper.doc

Here 3277256 is the inode, -rw-rw-r-- encodes type and permissions, 1 is the link count, owner and group follow, 0 is size in bytes, then date, time and name.

For a directory the size field behaves differently — directories report the file system block size, normally bytes.

Reading the line with numbers: Take the line 3277256 -rw-rw-r-- 1 owner group 0 May 20 12:00 paper.doc. Column 1 3277256 is the inode card number. Column 2 -rw-rw-r-- is type plus nine permission bits discussed in 5.2. Column 3 1 is link count — one name points here. Columns 4–5 owner group name who may use the first two permission triplets. Column 6 0 is size; a fresh touch result. Columns 7–9 are month, day and clock time of last content change. Column 10 is the label paper.doc. Add -i to see column 1; omit -i and the same line starts at column 2.

5.1.3 Creating Paths and Observing New Inodes

Creating always allocates a new inode. Demonstrations in the session used:

  • mkdir dir — make one directory in the current directory. Fails with "No such file or directory" if a parent in the path does not exist.
  • mkdir -p bits/Goa — the -p flag means "make parents as needed": every missing directory in the path is created. This flag is essential when you want to build a deep hierarchy in one command.
  • touch paper.doc — create an empty regular file. A freshly created file shows size and the current date and time.

After each creation, ls -li shows a fresh inode. Examples noted were 3277256 for a file named paper.doc and 327265 for a directory — concrete proof that files and directories each receive their own inode from the same number space.

Scope — when a new inode appears and when it does not: A new inode is allocated by mkdir, touch for a new name, cp and mknod. It is not allocated by mv inside one file system (the same card gets a new label), by chmod or chown (fields inside the same card change), or by appending with >> (blocks are added but the card number stays). If you copy across file systems, a new inode must appear because each file system has its own number space. Inode numbers are recycled only after the link count reaches zero and no process holds the file open.

Visual intuition: picture a directory as a two-column sheet — left column names you read, right column small integers. The -i flag unhides that right column. A second sheet, the inode table, lists those integers in order, each row holding the ten-character type and permissions, owner, group, size, three timestamps, link count and a list of disk block addresses. Looking up a name is two hops: name to integer, integer to row.

5.1.4 Worked Examples

Example 1 — Paper document in bits/Goa (full trace). Goal: obtain the inode number of paper.doc stored under Goa. Steps walked through:

  1. Try mkdir bits/Goa without -p when bits does not exist — shell prints mkdir: cannot create directory 'bits/Goa': No such file or directory. No inode allocated because the parent lookup fails.
  2. Run mkdir -p bits/Goa — kernel creates bits (inode e.g., 327264) then bits/Goa (inode e.g., 327265). Each mkdir returns a new inode.
  3. Enter the target directory with cd bits/Goa.
  4. Run touch paper.doc — allocates inode 3277256, ls -l shows -rw-rw-r-- 1 user group 0 May 20 12:00 paper.doc with size 0.
  5. Run ls -i paper.doc — prints 3277256 paper.doc. Run ls -li — prints 3277256 -rw-rw-r-- 1 user group 0 May 20 12:00 paper.doc with inode as the added first column. Answer bolded: inode = 3277256. Sense-check: a second touch on the same name does not change the number; only a new name gets a new number.

Example 2 — Incremental inode allocation. Create a new directory sample next to the file inside Goa and list again:

3277256  paper.doc
327265   sample/

The directory receives a distinct inode 327265 and the columns for size and permissions are populated at the same time. If you run stat paper.doc and stat sample you see Inode: 3277256 with Links: 1 and Inode: 327265 with Links: 2 (directories carry . and .. links). The gap between numbers is normal; allocation is not strictly consecutive across the whole volume because other objects may be created in between.

5.1.5 Student Questions and Answers

Q: What option should I provide to ls to display the inode number? A: Use -i. The i is the first letter of inode. ls -i shows inode plus name; ls -li shows inode plus the full long listing. The first column you see after adding -i is the inode number. The confusion sometimes arose from reading i as "information" — the correction is that i always means inode in this context.

Q: If I use ls -i do I still get permissions, ownership and size? A: No. ls -i shows only the inode and the name. Add -l to get the full metadata. ls -li is the combination most used in this session. Think of -i as "show card numbers" and -l as "show card details"; you combine them when you want both.

Pitfalls — inode versus name: 1) Thinking mv changes the inode — it does not within one file system; only the name moves. 2) Reading ls -i and expecting permission columns — they only appear with -l. 3) Assuming inode numbers are small — user files get six or seven digits, while /dev device nodes get two or three digits because they were allocated early at system install. 4) Expecting size 0 to mean "no inode" — even empty files have a card and a number.

Recap — cards and labels: The inode number is the kernel's true file identity, a positive integer st_ino; the name is a directory label that points to it. A new object always gets a new inode; a rename or permission change does not. The next section opens that card and reads its fields column by column in ls -l.

5.2 The Long Listing — What Every Column Means

Hook — one line that tells the whole story: You can learn ownership, who may read or write, how many names point at the data, how big it is, when it last changed and what kind of object it is — all without opening the file — if you can read one ls -l line. This section decodes that line left to right so every later discussion of permissions, links and sizes rests on a firm picture.

Intuition — passport stamp line: Think of ls -l as a passport stamp line for each object. The stamp shows the document type at the far left, then nine visa ticks, then how many travel names use this passport, then who owns it, how heavy the luggage is, when it was last stamped and finally the name on the cover. Once you know the stamp order, you never mix the country code with the luggage weight.

The long listing is the primary way to read file metadata without opening the inode directly. ls -l prints one line per entry; ls -li prepends the inode. Every column has a fixed meaning, and the session went column by column so that later discussions of permissions, links and sizes would make sense.

5.2.1 Column by Column Anatomy

Formalize — fixed columns of ls -li: Reading left to right, ls -li prints eight to nine fields in fixed order: inode, type and permission field, link count, owner, group, size, date and time, name. When you use ls -l without -i, the inode column is simply omitted and the remaining columns shift left but keep their meaning. Link count is an integer . Size is in bytes for regular files and in bytes of directory structure for directories. Date and time is mtime by default; ls -lc shows ctime and ls -lu shows atime in that same column.

For a line produced by ls -li, reading left to right:

  1. Inode number — integer identifier, present only with -i.
  2. Type and permission field — ten characters, e.g., -rw-rw-r-- or drwxr-xr-x. Character one is the file type; characters two through ten are the permission triplets.
  3. Link count — integer . For regular files it counts hard links; for directories it counts internal references including . and ...
  4. Owner — account name that owns the object (st_uid mapped to a name).
  5. Group — group name to which the owner belongs at creation (st_gid mapped to a name). In the demonstration each user was placed in a private group, so owner and group often matched at first. Listing another location where files belonged to different users showed this field changing.
  6. Size — in bytes for regular files (st_size); the file system block size for a freshly created empty directory. A directory at does not mean it contains bytes of user data — it is the space taken by the directory structure itself.
  7. Modification date and time — month, day, clock time of the last content change (mtime).
  8. Name — the directory entry that points to the inode.

The session emphasized that even directories are treated as files in Linux, so their name field is not a special case — it is the same final column.

5.2.2 The Ten-Character Type and Permission Field

Formalize — counting to ten: The first character is type; the next nine are three permission triplets. Counting positions avoids mixing them:

This string has length ten. Position one encodes type; positions two to ten encode permissions. Counting them helps avoid confusion:

position: 1  2 3 4  5 6 7  8 9 10
example:  -  r w -  r w -  r - -
meaning: type  user   group  others

The nine permission characters are grouped as three triplets: user (owner), group, others. Each triplet contains r, w, x or - in that order. A dash in positions two through ten means that particular permission is absent, which is distinct from the dash in position one that means "regular file".

Scope — dash means two different things: A - in position 1 is a type code that means regular file. A - in positions 2–10 is a permission code that means that one of r, w, x is not granted. In d rwx r-x r-- the leading d is type directory, the three rwx groups are permissions. Confusing these two uses of - is the most common reading error; counting positions fixes it.

Visual intuition: picture the ten-character field as ten little lamps. Lamp 1 colour tells the object family (-, d, c, b, l, p, s). Lamps 2–4 light r, w, x for the owner, 5–7 for the group, 8–10 for others. A dark lamp (-) is simply off. Example drwxr-xr-x lights all three for owner, r-x for group, r-x for others — a typical directory.

5.2.3 Owner, Group, Size and Timestamps in Depth

Owner and group. At creation the owner is the effective user who ran the creation command; the group is that user's primary group. Because the demonstration system created each user in a separate group, ls -l initially showed the same string in both columns. Moving to a shared area with files created by other accounts made the distinction visible: owner changed, group changed, and the permission triplets then governed who could do what. Under the surface these are numeric IDs st_uid and st_gid looked up in /etc/passwd and /etc/group for display.

Size. For a regular file, size is the logical byte count (st_size). For an empty file created with touch, it is 0. For a directory it is almost always 4096, the allocation unit for the directory's own table of names. A follow-up example showed three regular files inside a directory, each with its own small size (e.g., 12, 45, 120), while the directory entry itself still reported 4096. Writing more entries into the directory can later grow it to 8192, but never shrink it to reflect user data size.

Date, time and name. The timestamp shown by default is the last content modification time (mtime). Other timestamps exist — access time (atime) and change time (ctime) — and are discussed in 5.7. The final column is always the name that maps to the inode. Even directories use the same final column; the type character is what tells you it is a container.

Assumptions and scope — when size and owner matter: Size is exact for regular files but structural for directories; do not sum directory 4096 values to estimate disk use — use du. Owner and group control the first two permission triplets only for names that match those IDs; every other user falls into others. Times are shown in local time and update only on the events described in 5.7; a permission change does not update mtime.

5.2.4 Worked Examples

Example 1 — Empty paper.doc (decoded). After touch paper.doc, ls -l reported -rw-rw-r-- 1 alice alice 0 May 20 12:00 paper.doc and ls -li added 3277256 at the front. Breaking it down:

  • Position 1 - → regular file.
  • Chars 2–4 rw- → owner alice may read and write, not execute ().
  • Chars 5–7 rw- → group alice may read and write.
  • Chars 8–10 r-- → others may read only ().
  • Link count 1 → one name points here.
  • Owner alice, group alice, size 0, date May 20 12:00, name paper.doc. Answer: type regular, permissions rw-rw-r--, link count 1, size 0. Sense-check: empty file really is 0, not 4096; if it showed 4096 you would be looking at a directory line.

Example 2 — Directory versus file sizes. After mkdir -p bits/Goa, ls -l in the parent showed drwxr-xr-x 2 alice alice 4096 May 20 12:00 bits while ls -l bits/Goa showed -rw-rw-r-- 1 alice alice 0 May 20 12:00 paper.doc. The 4096 for bits is the directory's own block, not the sum of what is inside it. Creating three small files inside Goa with sizes 10, 20, 30 still leaves Goa at 4096 until the directory table itself needs a second block. This contrast teaches that regular size is content size, directory size is structure size.

Example 3 — Ownership variation across the file system. Listing the class directory after creations by other accounts showed owner changing to bob or carol while the permission string stayed similar. Then ls -li in a temporary location with files from different users showed 3277300 -rw-r--r-- 1 bob students 45 May 20 12:10 report.txt next to 3277301 -rw-rw---- 1 carol staff 120 May 20 12:11 data.bin. Inode stayed unique, owner and group columns moved, and the permission triplets then decided who could do what for each line.

5.2.5 Student Questions and Answers

Q: The second column shows bits and also names like an account name. How is bits different from the owner name? A: The second column is not a single value. Its first character is file type (-, d, etc.), the remaining nine are permissions. The owner column is several columns to the right — it shows which account owns the object. bits in the name column is a directory name; the same string appearing earlier in the line as part of the permission field is a coincidence of letters. Counting positions from the left keeps the two meanings separate. The string rwx contains none of the letters in bits — the overlap is only in your eye when columns are close.

Q: What do T, R, X stand for in that display? Does D mean delete? A: No. r means read, w means write, x means execute. d in position one means the object is a directory; - means regular file. A dash inside the nine permission slots means that specific permission is not granted. There is no T or D for delete in this field; t and T appear only as special bits on directories in other listings, not in the basic field taught here.

Pitfalls — misreading the line: 1) Thinking position 1 - is a permission — it is type; permissions start at position 2. 2) Adding -i and thinking ownership columns disappear — they stay, inode is simply added on the left. 3) Reading directory size 4096 as user-data size — it is the directory's own block. 4) Expecting ls -l date to be creation time — Linux shows mtime by default; ctime is inode change, not creation.

Recap — stamps in order: A long line is inode (with -i), then type, then three rwx triplets, then link count, owner, group, size, mtime and name. Read type first, count to ten for permissions, then check who owns the object before you decide which triplet applies to you. The next section opens position 1 alone and shows the full family of types.

5.3 File Types — The First Character

Hook — the same file system speaks hardware and documents: In Linux the path /dev/sda looks like a file and ls -l shows it like a file, yet reading it reads a disk, not a document. The first character of the ten-character field is what tells you whether you are looking at user data, a folder, a disk, a terminal, or a shortcut — before you ever try to open it.

Intuition — uniforms behind one reception desk: Think of the file system as a reception desk that hands you objects in identical envelopes. The envelope's first letter is the uniform: - plain document, d folder, c clerk who hands you characters one by one, b warehouse that hands you boxes, l shortcut slip that says "ask next door", p speaking tube, s telephone socket. The desk is the same, the uniforms tell you how to talk to what is behind it. Where the picture stops: permissions and sizes still apply, but for a device they describe who may talk to the hardware, not how many bytes are stored.

The first character of the ten-character field classifies the object. Linux exposes many kinds of objects through the same file system interface, so learning this field lets you distinguish what you are looking at without opening it.

5.3.1 Regular Files and Directories

Two everyday types: - is a regular file — any file created with touch, an editor, a compiler output, or a downloaded document. Text files with readable characters and binary executables both show -; the system does not distinguish them by type, only by content. d is a directory — a container whose data is a table of names to inode numbers. Both receive inodes from the same space; their size fields simply mean different things.

  • -regular file. Any file created with touch, an editor, a compiler output, or a downloaded document counts as regular. Text files with readable characters and binary executables both show - — the system does not distinguish them by type, only by content. A cat of a binary such as a command in the system area produces unreadable bytes, confirming that - covers both readable and non-readable contents. Executable programs are still regular files; they simply carry x in their permission triplet so the kernel will try to run them.
  • ddirectory. A container for names that point to inodes. Real-world: a folder that can hold any number of files and subdirectories. Its x permission means you may traverse it with cd.

The two most common types you will see day to day are - and d, and the session noted they are expected to dominate any long listing. In a typical home directory, 90 percent of lines show one of these two.

5.3.2 Device Files — Character (c) and Block (b)

Hardware behind the same interface: To see the rarer types, the session listed /dev, the directory that exposes hardware. The same ls -li columns appear, but size is replaced by major and minor device numbers. The counts below come from that live listing and match the reference tables for device nodes.

To see the rarer types, the session listed /dev, the directory that exposes hardware:

  • ccharacter device file. Data moves as a stream of characters, one at a time, with no block buffering. Examples discussed were serial ports, parallel ports, terminals identified as tty (tty0, tty1, ttyS0), pseudo-terminals pty, and the console. Because they transmit character by character, they are called character devices. Reading them yields a stream; seeking is often not allowed.
  • bblock device file. Data moves in fixed-size blocks, typically 512 or 4096 bytes, with kernel buffering. Examples were disks shown as sda, sda1, sda2 and loop devices loop0. Hard disks are the canonical block device: the file system reads and writes blocks, not single characters. Block devices support random access by block number.

Running ls -li /dev showed a striking difference: inode numbers for device nodes were very small (two or three digits such as 14 for console, 5 for tty) compared with six- or seven-digit inodes for user-created files (e.g., 3277256). That pattern reflects early allocation of device inodes at system install versus dynamic allocation for user data. The ls -l size column for devices instead showed 5, 1 style major-minor pairs.

  • lsymbolic link (also called soft link). Shown as l in the type field and usually displayed as name -> target with a distinct color. A symbolic link is a tiny file whose content is the path to another object. Real-world: the Windows shortcut is the closest analogy; l in the type field is the L you may see in some fonts. Its size is the length of the target path.
  • pnamed pipe (FIFO). Created with mkfifo for inter-process communication where one process writes and another reads in first-in first-out order. The p type appears only when a pipe file is created; it has no persistent presence in /dev by default.
  • ssocket (Unix domain socket). Created by system services for communication between processes, often in /run or /tmp. Used in networking code and desktop services. Like p, it appears where a program creates it.

The session noted that a pipe socket file and a named pipe file are tied to inter-process mechanisms: named pipes, regular pipes, shared memory and sockets are different ways two otherwise isolated processes can exchange data, a topic returned to in later courses on network programming. No p or s entry was found in /dev during the live listing, which is normal — they appear where programs create them, not as permanent device nodes.

Scope — when each type appears: You will see - and d everywhere. You will see c and b concentrated in /dev and sometimes in containers. You will see l wherever a shortcut, library alias or version link exists. You will see p and s only in IPC or service areas such as /tmp, /run or a build directory. If you run ls -li on a random home file and expect c or b, you will not find them — that absence is normal.

5.3.4 Exploring /dev and Capturing Output with Redirection

Redirection as capture: The session turned the /dev listing into a small exercise in output capture. The shell operator > redirects standard output from the screen into a file.

The session turned the /dev listing into a small exercise in redirection:

ls -li /dev > output.txt

Here > is the output redirection operator: the standard output of ls -li /dev is written into the regular file output.txt instead of the terminal. After the command, cat output.txt or ls -l output.txt confirms the capture, including the small inode numbers at the left and the mixed type characters c, b, l throughout. If output.txt already existed it is truncated first; >> would append instead.

A follow-up discussion captured two device-oriented views:

  • Character devices such as tty and ports appeared as c with major-minor numbers.
  • Block devices such as sda and sda1 appeared as b with major-minor numbers and small inodes.

These examples made clear that the file system is not only for user documents — it is also the uniform interface to hardware. Systems code, drivers and containers all rely on that uniformity.

Worked capture trace: Run ls -li /dev | head to see lines like 14 crw--w---- 1 root tty 5, 0 May 20 12:00 console (type c, inode 14, major 5 minor 0) and 1024 brw-rw---- 1 root disk 8, 0 May 20 12:00 sda (type b, inode 1024). Then ls -li /dev > output.txt and ls -l output.txt shows -rw-rw-r-- 1 alice alice 18432 May 20 12:01 output.txt — a regular file - now holding the snapshot. cat output.txt reproduces the same mixed c/b/l lines you saw on screen. Bolded result: redirection copies the listing into a regular file without changing any type character in /dev.

5.3.5 Student Questions and Answers

Q: What does C indicate in that first column? What about L? A: c means character device file — communication happens as a character stream, like a serial or parallel port or a terminal (tty, console). l (displayed as L in some fonts) means symbolic link — an entry that points to another file or directory. A quick test is ls -l /dev/console shows c while ls -l mylink shows l and mylink -> target with arrow.

Q: What does B stand for and what is an example? A: b means block device file — data moves in blocks. A hard disk (sda, sda1, partition sda2) is the standard example discussed. Disks transfer blocks of memory between the device and the system. ls -l /dev/sda shows b and ls -l /dev/tty shows c for contrast.

Q: How do we capture the listing output into a file? A: Add redirection: ls -li /dev > output.txt. The > symbol takes the output that would normally appear on the screen and writes it into output.txt. Use >> to append without overwriting. The resulting file can then be viewed with cat or shared; it is a regular file - even though its contents describe many device types.

Q: Does p or s ever appear in /dev? A: p (named pipe, FIFO) and s (Unix domain socket) are valid types but were not present in the /dev sample shown. They appear where a program explicitly creates a pipe or socket file, for instance after mkfifo mypipe you see prw-r--r-- or after a service starts you see srwxr-xr-x in /run. Their absence in /dev is normal.

Pitfalls — reading type: 1) Thinking cat decides type — it shows content, not type; both text and binary executables share -. 2) Expecting p or s inside /dev routinely — they live elsewhere. 3) Reading - as "no type" — it is a real type, regular. 4) Forgetting that > overwrites — use >> when you want to keep earlier captures.

Recap — uniforms in position 1: Position 1 shows the family: - document, d folder, c stream hardware, b block hardware, l shortcut, p pipe, s socket. The most examinable contrast is c versus b by transfer unit (characters versus blocks) and l by its arrow and separate inode, seen next in permissions and links.

5.4 File Permissions — rwx for User, Group and Others

Hook — the permission denied you already met: You typed cat file, you own the file, yet the shell said "Permission denied." The nine rwx bits are why — they decide who may read, write or enter, and the ten-character field shows the answer at a glance. Learning to split that field into three triplets turns the error from mystery to checklist.

Intuition — apartment keys: Think of a building with three key rings: your personal ring (user), the floor's shared ring (group) and a visitor ring (others). Each ring has three keys: r front-door read, w renovation write, x stairwell execute. The superintendent (owner name) decides which keys sit on which ring. Your name decides which ring you get to try. Where the picture stops: on a regular file x means "may run as program"; on a directory x means "may step inside" — same key, different lock.

Every file system object carries nine permission bits that decide who can read, write and execute it. Those bits are shown as nine characters grouped into three triplets, and the session spent substantial time decoding them because permission errors are the most common source of "permission denied" surprises.

5.4.1 Meaning of r, w and x

Three rights, two objects: r, w, x are the only permission letters, but their effect depends on whether the object is a file or a directory. The table form helps:

  • rread. If r is present in your triplet, you can list a directory or view a file's contents. Without r, cat file fails with permission denied. For a directory, r lets you list names inside; you still need x to enter.
  • wwrite. If w is present, you can modify the object's contents. For a file this means editing or appending; for a directory it means creating or deleting names inside. You can delete a file from a directory if you have w on the directory, even without w on the file itself.
  • xexecute. If x is present on a regular file, you can run it as a program (./script.sh). If x is present on a directory, you can traverse it (enter it with cd or pass through it to a subpath). A normal text file such as output.txt or sample.txt usually shows - in the x position because the system treats it as data, not code. Trying to ./output.txt fails either from missing x or because the content is not executable code.

A dash - inside the nine slots always means "this permission is not granted" and should not be confused with the leading dash that means "regular file".

5.4.2 The Three Triplets — User, Group, Others

Who gets which triplet: The kernel picks exactly one triplet to evaluate, in order: if your user ID matches the owner, you get user; else if your group ID matches the file's group, you get group; else you get others. It does not add them together.

Reading the permission string from left to right after the type character:

-rwx rwx rwx
  ^   ^   ^
 user group others
 chars 2-4 chars 5-7 chars 8-10
  • User (owner) — the first triplet (characters 2–4). Controls what the owning account can do.
  • Group — the second triplet (characters 5–7). Controls what members of the file's group can do. In the demonstration each user started in a private group, but the concept allows a project group where several accounts share one group entry.
  • Others — the third triplet (characters 8–10). Controls what everyone else can do. Real-world: this is how a file shared on a lab machine can be made readable campus-wide while remaining writable only to the owner.

For output.txt the session noted permissions rw- rw- r--. The owner can read and write, group members can read and write, others can only read. No triplet contained x because the file was plain text. The numeric view of that same string is 664 ( , ).

Visual intuition: sketch three vertical columns labeled User, Group, Others, each with three rows r, w, x. A tick means the lamp is lit, - means dark. For rw-rw-r-- the User column has ticks on r and w, Group on r and w, Others on r alone.

5.4.3 Worked Examples — Reading Permission Strings

Example 1 — rw- rw- r-- (664). Splitting -rw-rw-r-- after the leading -:

  • Chars 2–4 rw- → user read and write, no execute. Numeric . User may cat and echo >> but not ./file.
  • Chars 5–7 rw- → group read and write, no execute. Same . Teammates in the file's group may edit.
  • Chars 8–10 r-- → others read only. Numeric . Anyone else may cat but may not edit. Bolded summary: 664 = rw- rw- r--, no execute anywhere.

Example 2 — rwx r-- --x (741 pattern). Splitting after type: rwx for user ( — full control), r-- for group ( — read only), --x for others ( — execute only, cannot read). Used to show each position is independent: an x in others does not grant r. Trying cat as other would fail (no r), but ./file would be attempted if the content were a program. This odd pattern was drilled to prove x alone does not imply r.

Example 3 — rwxrwxrwx (777). All three triplets grant rwx ( each). Owner, group and others may read, write and execute. Full 777 on a directory means anyone may create and remove names inside; on a data file it means anyone may overwrite the content. While useful for illustration, the session noted this is rarely appropriate for regular data because it allows anyone to modify the file. Safer defaults are 664 for files and 775 or 755 for directories.

5.4.4 Industry and Pedagogical Notes

Real-world: in a team the second triplet becomes important. You can place all teammates in one group (groupadd team; usermod -aG team alice) and grant that group rw- on shared source files while leaving others at r-- or ---. The third triplet is then the public boundary. Platform teams set home directories to 750 (others none) and shared docs to 664 so the semester project passes permissions review.

The session flagged the permission decode as examination-relevant: being able to translate a ten-character string into type plus three triplets, and then into who can do what, was presented as a core skill. Examiners often give a string and ask "may user X run cat?" — you answer by picking the right triplet first.

Assumptions and scope: rwx on a directory is not the same as on a file: directory r lists names, x traverses, w creates or deletes entries. Removing r on a file does not hide its name in a directory listing; the directory's r controls that. Permission checks are by UID and GID only; background tools running as the same user share the same rights.

5.4.5 Student Questions and Answers

Q: The owner column shows account names. How does that connect to the permission triplets? A: The owner name tells whose rwx triplet is evaluated as "user". The group name tells whose rwx triplet is evaluated as "group". Everyone else falls into "others". So a line tells both the identity (owner and group) and the rights (the three triplets) in one place. Example: -rwxr--r-- 1 bob staff ... script.sh — if you log in as bob you use rwx, if you are in staff but not bob you use r--, otherwise you use r--.

Q: Why does a text file show no x? A: The system marks plain text as data, not code. x is reserved for files you intend to execute. The dash in the x slot for a text file simply means execute is not granted — you can still read and write it. If you want to run a shell script you add x with chmod u+x script.sh; the type stays - because a runnable script is still a regular file.

Pitfalls — reading rwx: 1) Adding triplets together — the kernel picks one, not the sum. 2) Thinking - in position 1 is a permission — it is type. 3) Expecting w on a file to let you delete it — delete is controlled by the directory's w. 4) Giving rwx to others on secret data — o-rwx with chmod removes it safely.

Recap — pick the right triplet: Read type at position 1, split the next nine into user, group and others, pick the triplet that matches who you are, then read r as view, w as edit, x as run or traverse. In the next two sections you will learn to set those nine bits two ways: all at once with three octal digits, or one tick at a time with symbolic mode.

5.5 Changing Permissions — Absolute (Octal) Mode

Hook — one number to set nine switches: Nine rwx lamps could be flipped one by one, but when you know the final pattern you want, three digits r=4 w=2 x=1 set them all at once. Absolute mode is that shortcut — three octal digits, one per triplet, overwriting everything in a single command.

Intuition — three dials, not nine buttons: Think of three dials labelled User, Group, Others, each dial numbered 0 to 7. Each number is just a compact way to write three switches: 4 flips r on, 2 flips w on, 1 flips x on, and you add what you want. Dial 6 = 4+2 lights r and w; dial 7 = 4+2+1 lights all three. Where the picture stops: the digits look decimal, but they are octal — a digit 8 or 9 does not exist and a binary string like 110 cannot be typed as one digit.

Permissions are not fixed at creation. The command that changes them is chmod, short for "change mode". The absolute mode sets all nine bits at once using three octal digits.

5.5.1 chmod Syntax and Who Can Run It

Absolute form — overwrite all nine: chmod permissions file-or-dir where permissions is three octal digits 07, each summarizing one triplet. The session example chmod 000 more.txt writes 0 0 0 over user, group and others, turning all nine lamps off.

The general absolute form is:

chmod permissions file-or-dir

where permissions is three octal digits (examples: 000, 640, 755) and file-or-dir is the target. An example covered was chmod 000 more.txt to strip all rights. Each digit is base eight; the valid range is 0 to 7 only.

Only two actors are allowed to run this command on a file:

  • The owner of the file (st_uid matches your effective UID).
  • The superuser (root, UID 0 with elevated privileges).

Anyone else who tries to change permissions will receive chmod: changing permissions of 'file': Operation not permitted, even if they can read the file. Ownership is checked before the bits are touched.

5.5.2 Octal Mapping — r = 4, w = 2, x = 1

From three lamps to one digit: Each triplet maps to one octal digit by weighting:

Each triplet maps to a single octal digit through by weighting the bits:

where indicate absence or presence of that permission, verbalized in the session as "one and one and one" for a full rwx triplet.

Concrete binary to octal table:

Binary Octal Meaning
000 no permission
001 execute only
010 write only
011 write and execute
100 read only
101 read and execute
110 read and write
111 read, write and execute

The digit 7 comes from . The digit 6 comes from . The digit 4 is . The digit 1 is .

The three octal digits are ordered as . So 741 means:

The session repeatedly stressed that the value is written in octal (base eight), not binary. A question about whether binary strings like 100 could be typed directly was tested and the answer was no — chmod 100 is read as octal digits, and a mode such as 100 means , not binary one-zero-zero. An attempt to give a binary string as an octal argument produced "invalid mode". The correct habit is to compute each digit - from rwx and then write three digits left to right as user, group, others.

Visual intuition: sketch three rows user, group, others, each with three boxes r w x. Tick the boxes you want, read tick as 1, compute per row, write the three results in order. Ticks 111, 100, 001 become 7, 4, 1.

Scope — absolute overwrites: Absolute mode always overwrites all nine bits. If you type chmod 640 file when you only meant to add x for others, you also change user and group bits to 6 and 4, even if they were different before. To change one bit without touching the rest, use relative mode in 5.6.

5.5.3 Worked Examples — Step by Step

Example 1 — Remove everything: chmod 000. Start from a file that showed rw-rw-r-- after touch.

chmod 000 more.txt
ls -l more.txt  -->  ----------  (all dashes in permission slots)

Computation: user , group , others . Consequence: cat more.txt returns "permission denied" and writing with echo hello > more.txt also fails for non-owners. Restoring later with a higher mode is still allowed because the owner retains the right to chmod even when r is off.

Example 2 — Give the owner everything: chmod 700. Continuing on the same file:

chmod 700 more.txt
ls -l more.txt  -->  -rwx------ 

Meaning: user (), group , others . Now cat > more.txt succeeds for the owner and writes hello inside. cat more.txt reads it back. Attempting ./more.txt still prints cannot execute binary file or command not found because the content is plain text, but the x bit is correctly lit — permission and content are separate.

Example 3 — Owner all, group read and write: chmod 760. Question: give owner and group while leaving others with nothing.

  • Owner rwx -> ()
  • Group rw- -> ()
  • Others --- ->
chmod 760 more.txt
ls -l more.txt  -->  -rwxrw---- 

Verification: ls -l shows rwx for user and rw- for group exactly as planned. A group member may now cat and edit; others see permission denied because their triplet is ---.

Example 4 — Owner all, group read only, others execute only: chmod 741. Sub-problem: owner needs rwx , group needs r-- , others need --x .

chmod 741 more.txt
ls -l more.txt  -->  -rwxr----x

Reading left to right after the type: rwx for user (), r-- for group (), --x for others (). Learners predicted 741 before running it, and the listing confirmed it. Trying cat as other still fails (no r), but searching a directory with that bit would succeed for others.

Example 5 — Give everyone read and write, no execute: chmod 666.

chmod 666 more.txt
ls -l more.txt  -->  -rw-rw-rw-

Each triplet rw- (). The execute highlight disappears in colored ls and the file is no longer shown as executable. Group and others may now edit the file's content; no one may ./more.txt until an x is added.

Example 6 — Default regular file: 664. When a plain file is created with touch 1.txt, ls -l shows rw-rw-r--.

  • Type -, then rw- ->
  • rw- ->
  • r-- -> ()

So absolute mode 664 maps to: This is the umask 002 default after touch: user and group get rw-, others get r--. A stricter umask 022 would give 644 ().

Example 7 — Add execute while keeping other bits: from 664 to 774. Exercise: add execute for user and group while keeping other rights. From rw-rw-r-- () add x to the first two triplets:

  • (add )
  • (add )
  • unchanged

Result 774 -> rwxrwxr--.

chmod 774 more.txt
ls -l more.txt --> -rwxrwxr--

Absolute mode still overwrites — you must compute all three digits. To add one x without recomputing, the session next introduces chmod g+x style relative mode.

5.5.4 Common Pitfall — Binary vs Octal

Pitfall — binary is not octal: A learner asked whether 110 could be typed as one digit. The live test showed chmod 100 does not mean binary 100 (). It means octal digits 1, 0, 0--x ------ ------ (only others x if read as 001 000 000 would be 100? Actually 1 0 0 is --x --- ---). The system rejects a three-character binary string as a single digit with "invalid mode: 110". Correct habit: convert each triplet rwx to via and write exactly three digits. Digits 8 and 9 are never valid.

5.5.5 Student Questions and Answers

Q: Can the value 100 be used directly as a binary number with chmod? A: No. What you type is three octal digits. 100 is read as digit 1 for user, 0 for group, 0 for others, which gives --x for the owner only (if typed as 100 it is 1 0 0). The conversion must go binary triplet → decimal first, then that decimal digit is typed. A binary string alone does not work and produces an invalid mode error. Think "binary is the working, octal is the typing."

Q: If I give chmod 664, what does that mean on screen? A: It maps to rw-rw-r-- (with leading - for regular). User rw- (), group rw- (), others r-- (). That is the default you see right after touch for a regular file under the common umask. The calculation is , .

Q: How do I add execute to a file that already has read and write without recomputing everything? A: In absolute mode you must recompute all three digits — the command overwrites them. To add one bit without recomputing, use relative mode (next section). For example, starting from 664, chmod 774 rewrites the first two digits to add execute, but chmod u+x,g+x file adds x to user and group without touching others. The next section drills that style.

Pitfalls — absolute mode: 1) Thinking you can type binary 110 as one digit — you must convert to 6. 2) Forgetting the overwrite rule — chmod 640 clears bits you did not mention. 3) Mixing up order — digits are user, group, others, not the reverse. 4) Trying as non-owner — permission denied from chmod itself before any bit changes.

Recap — three dials 4-2-1: Each rwx is a binary triplet, each digit is in , three digits left to right are user, group, others. Master table 07 and you can read 664 as rw-rw-r-- and write rwxr----x as 741 in either direction. Relative mode next gives you a scalpel when absolute's overwrite is too blunt.

5.6 Changing Permissions — Relative (Symbolic) Mode

Hook — the small fix: You set a file to 664 and then realize reviewers also need to run it. Absolute mode would make you recompute 775 and rewrite all three digits. Relative mode lets you say "add x for group and others and leave the rest alone" in one readable command.

Intuition — stickers on dials: If absolute mode replaces three dials, relative mode sticks a note on one dial: "add x here" or "remove w there." The other dials stay exactly as they were. You address a dial with u (your ring), g (floor ring), o (visitor ring) or a (all rings), choose + or -, and name the keys r, w, x. Where the picture stops: = exists but was not drilled here — it sets a triplet exactly and clears the other bits in that triplet, like absolute but per category.

The absolute mode rewrites all three digits. The relative mode, also called symbolic mode, is finer: it adds or removes one permission for one category at a time, leaving other bits untouched. Learners found this style more readable for small adjustments.

5.6.1 Syntax — Category, Operation, Permission

Symbolic sentence — who, how, what: The pattern reads like a sentence: category (who), operation (how), permission (what). The session wrote it as category permission:

The pattern is:

chmod category operation permission file

overlaid on the session's description as category permission:

  • Category (who): u user, g group, o others, a all. Combinations like ug, go, uo are allowed. a is shorthand for ugo — all three categories together.
  • Operation: + add permission, - remove permission, = set exactly (mentioned but not the focus; the session emphasized + and - which are idempotent).
  • Permission: r read, w write, x execute.

So chmod u+rwx more.txt reads as "for user, add read, write and execute". chmod g+r more.txt reads as "for group, add read". chmod o+x more.txt reads as "for others, add execute". You can combine permissions: u+rwx equals u+r,u+w,u+x in one token.

Scope — what = does: chmod u=rw file sets user to exactly rw- and clears user x if it was there, but leaves group and others untouched. That per-category overwrite is more surgical than absolute's three-digit overwrite, but still clears within the named category. The session used + and - to avoid that clearing.

5.6.2 Worked Examples — Incremental Construction

Building 741 step by step from 000 (the session's drill): Start from 000 (----------) on more.txt. After each chmod, ls -l was checked.

Step 1 — Give the owner everything:

chmod u+rwx more.txt
ls -l more.txt --> -rwx------   (u 7, g 0, o 0 = 700 equivalent)

Only user triplet changed from --- to rwx; group and others stayed ---.

Step 2 — Give the group read only:

chmod g+r more.txt
ls -l more.txt --> -rwxr-----   (u 7, g 4, o 0 = 740 equivalent)

Only r was lit in group; existing rwx for user untouched.

Step 3 — Give others execute only:

chmod o+x more.txt
ls -l more.txt --> -rwxr----x   (u 7, g 4, o 1 = 741)

This produced the same 741 pattern (rwx r-- --x) as the absolute 741 example, but built incrementally. Each + flipped only the requested lamp.

Step 4 — Give everyone everything:

chmod a+rwx more.txt
# equivalent to chmod ugo+rwx more.txt
ls -l more.txt --> -rwxrwxrwx  (777)

a+rwx lights rwx in all three triplets. The session noted a and ugo are synonyms; ugo+rwx does the same.

Step 5 — Remove everything:

chmod a-rwx more.txt
ls -l more.txt --> ----------  (000)

All nine lamps off again. Useful as a blank slate to demonstrate the next build.

Step 6 — Give everyone read, then add execute: Starting again from cleared bits:

chmod ugo+r more.txt   # order ugo, goU, etc. does not matter
ls -l more.txt --> -r--r--r--  (444)
chmod a+x more.txt
ls -l more.txt --> -r-xr-xr-x  (555, r-x per triplet)

ugo+r and ogu+r have the same effect — the system treats the set {u,g,o} as a whole. a+x then adds x alongside the r already there, yielding r-x. An earlier attempt to run chmod a+x on a file that already had a+rwx correctly did nothing new — x was already present. The session used that to show + is idempotent: adding a permission that is already there leaves the display unchanged.

The operation chmod o+x leaves the r bits alone and only flips the x in the third triplet, while chmod 741 overwrites all nine bits at once. That difference — modify versus overwrite — is the core reason to choose relative mode.

Bolded takeaway: Relative u+rwx, g+r, o+x and absolute 741 converge to -rwxr----x, one by incremental adds, the other by single overwrite.

5.6.3 Adding Versus Removing and Category Combinations

  • chmod g+w file — add write to group, leave user and others untouched. rw- rw- r-- (664) becomes rw- rwx r--? Actually only group w already present, so no change; from r-- r-- r-- it would become r-- rw- r--.
  • chmod o-r file — remove read from others if present; no error if r was already absent. From rwxrwxrwx it becomes rwxrwx--x.
  • chmod ug+r file — add read to both user and group in one command.
  • chmod og-x file — remove execute from others and group together.

The session illustrated that the category letters can appear in any order: ugo+r and ogu+r have the same effect. The permission letters can also be combined (rwx), so u+rwx is the same as u+r,u+w,u+x in sequence. You can chain clauses comma-separated: chmod u+rwx,g+rw,o+r file mixes who gets what in one call.

Real-world: a team review workflow was sketched: create source with u+rwx, give reviewers g+rw so they can read and annotate, and keep o+r or o+x minimal for managers who only need to run the built output. Release then uses o-rwx to close visitor access quickly without recomputing user and group.

Pitfalls — symbolic: 1) Missing category — chmod +r file means a+r with umask masking, not just user; always name u, g, o or a. 2) Thinking - signals error when removing a missing bit — it succeeds silently and leaves the display unchanged. 3) Using = when you meant +g=r clears w and x for group, g+r would keep them.

5.6.4 Interaction Between Absolute and Relative Modes

A practical tip given was to start new shared files with a sensible absolute default (often 664 for data, 755 = rwxr-xr-x for directories or scripts) and then fine-tune with relative operations. Absolute mode is faster when you know the final pattern; relative mode is safer when you only want to add or remove one bit without risking overwriting other bits you intended to keep. Both were demonstrated on the same more.txt file so learners could see the listing converge to identical results from either path.

Comparison in one view:

Need Absolute example Relative example Result
Start from 000, want 741 chmod 741 file chmod u+rwx,g+r,o+x file -rwxr----x
Add write for group only recompute to 742? no, must recalc all three chmod g+w file (touches only group) group r--rw-
Remove execute from others chmod 740 file (overwrites others) chmod o-x file (clears only that bit) others --x---

The session's advice: set the baseline with numbers, polish with symbols — numbers for known final states, symbols for live fixes during a lab.

5.6.5 Student Questions and Answers

Q: What category letters and operations do I use for relative mode? A: Category is u for user, g for group, o for others, or a/ugo for all. Operation is + to add permission and - to remove it. Permission is r, w or x. So chmod u+rwx file adds all three for the owner; chmod g+r file adds read for the group; chmod o+x file adds execute for others. Combine as chmod ug+rwx,o+x file for mixed targets.

Q: Does the order of categories matter, like ugo versus ogu? A: No. ugo+r, guo+r, oug+r all mean "user, group and others, add read" and produce -r--r--r-- from a cleared state. The system treats the set of categories as a whole. Only the permission letters' presence matters, their order rwx is conventional.

Q: If I run chmod a+x twice, does the second run change anything? A: No. Once x is present in each triplet, adding it again leaves the display unchanged. + only turns a missing r, w or x into a present one; - only clears a present one. Both are idempotent — repeating them does not toggle.

Recap — numbers versus symbols: Absolute chmod 741 overwrites user, group and others together; relative chmod u+rwx,g+r,o+x adds tick by tick and leaves unmentioned bits alone. Know both: use three digits when you can write the final pattern from memory, use u/g/o/a + - r/w/x when you need a quick, safe patch. The next section shows which clock each operation winds.

5.7 File Timestamps — Access, Modify and Change

Hook — three clocks on one card: A file has one creation moment but three clocks that tick for different reasons. Reading the file winds one clock, editing winds two, changing permissions winds a third. If you can tell those ticks apart, stat stops being confusing and make and backup decisions become clear.

Intuition — library card stamps: Think of atime as the librarian's "last borrowed" stamp (you opened the book), mtime as the author's "last rewritten" stamp (content changed), and ctime as the registrar's "card amended" stamp (any field on the identity card changed — permission, owner, link count, or a rewrite that also changes size and time). Changing the title on the card winds ctime alone; rewriting a chapter winds both mtime and ctime; just reading winds atime. Where the picture stops: ctime cannot be set by hand and is not creation time, even though the c may suggest it.

Beyond size and permissions, each inode tracks three times. Confusing them is common, so the session isolated each with explicit read and write operations and the stat command, and it corrected an early slide that swapped two ls options.

5.7.1 atime, mtime, ctime Defined

Three stamps, three triggers: Each stamp has one trigger and one ls/stat view. The mnemonic a for access, m for content modify, c for inode change keeps them distinct.

  • atimeaccess time. Updated when the file's contents are viewed or read. Reading with cat, less or opening in an editor advances atime. Even cp reading the source advances source atime.
  • mtimemodify time. Updated when the file's contents change. Editing with cat >, appending with echo >>, or overwriting via an editor advances mtime. This is what ls -l shows by default.
  • ctimechange time (also called inode change time). Updated when the inode metadata changes — permissions, ownership, link count, or any content change that necessarily changes metadata such as size and mtime. Crucially, ctime is not the creation time; it records the last time the inode structure itself was altered. You cannot set ctime directly; the kernel sets it on any inode write.

A mnemonic used was: a for access, m for content modification, c for inode change. Changing permissions with chmod advances c but not m; changing contents advances both m and c; viewing advances a. The reference texts note that modern mounts may delay atime with relatime for speed, but the logical rule stays.

5.7.2 Viewing Times — stat, ls -lc, ls -lu

Three commands expose the times:

  • stat file — full statistics. Example output for 2.txt included: file name, size, blocks, I/O block size , file type regular file, device id, inode number, links, access field showing the octal permission (e.g., Access: (0644/-rw-r--r--)), owner and group IDs, and three lines for access, modify and change times with second resolution. A sample access line looked like Access: 2024-05-20 12:04:53.123456789. Modify: and Change: lines follow with the same format.
  • ls -lc file — long listing that shows change time (ctime) in the date column, i.e., when the inode last changed. The c matches change.
  • ls -lu file — long listing that shows access time (atime) in the date column. The u matches use or access.

The session initially swapped these two in one slide and then corrected explicitly: ls -lc shows the inode change time, ls -lu shows the data access time. That correction was flagged as important to remember and is examinable: c = change, u = access.

Scope — which command shows which clock: ls -l alone shows mtime. Add -c to show ctime instead; add -u to show atime instead. Do not combine -c and -u — the last one wins. stat always shows all three together, so it is the arbiter when ls variants disagree.

5.7.3 How Operations Affect Each Stamp

Trace on file 2.txt (the session's demonstration): 2.txt was created empty with touch 2.txt, so all three stamps start close together, e.g., 12:02:00.

Step 1 — Read the file. Run cat 2.txt and then stat 2.txt. Only atime moves forward (example: from 12:02:00 to 12:04:53). mtime and ctime stay at 12:02:00 because neither content nor metadata changed. On a relatime mount the atime jump may appear only after a write or after a day has passed, but the logical expectation is "read winds atime alone."

Step 2 — Change permissions. Run chmod 000 2.txt and then stat 2.txt. ctime advances (example: 12:03:00 to 12:06:00, later to 12:08:00 on another chmod). atime and mtime do not change; content is untouched. The inode number itself also does not change — ctime records the change to the permission field inside the same inode, not the allocation of a new inode.

Step 3 — Change file contents. Run cat > 2.txt, type new lines such as hello and end with Ctrl-D, and then stat 2.txt. Both mtime and ctime advance to the same new value (example: both show 12:08:15) because new bytes change size and content time and therefore also amend the card. atime also updates on the next cat read.

Step 4 — Rename the file. Run mv 2.txt 2_renamed.txt and then stat 2_renamed.txt. The inode number remains the same (e.g., still 3277310). Content timestamps mtime and ctime for the file are not advanced by the rename itself; ctime for the directory that lost and gained the name does advance, as does mtime for those directories. The session used this to prove that a name change is a directory operation, not a file-content operation.

These steps lead to the rule stated as a table:

Operation atime mtime ctime inode number
cat read advances same
chmod, chown, ln advances same
echo >> or cat > write advances advances same
mv within same file system — (file) / advances (dirs) same

A name change, a permission change and an ownership change all advance ctime for the objects whose card changed but only content edits advance mtime. Renaming was cited as the classic case where the inode number stays the same while the directory's structure changes.

5.7.4 Worked Examples

Example 1 — Isolated access advance. With 2.txt showing Access: 2024-05-20 12:04:53 and Modify: 12:02:00, Change: 12:03:00, running cat 2.txt and checking again showed Access: 12:04:55 (moved ahead by seconds), while Modify: and Change: stayed fixed at 12:02:00 and 12:03:00. The difference was visible at second resolution in stat output. If relatime is active, repeat after touch or wait for the next day to see the jump.

Example 2 — Permission change advances only ctime. Starting from Change: 12:03:00, chmod 000 2.txt moved Change: to 12:06:00 while Access: and Modify: held. A second chmod 777 2.txt moved Change: again to 12:08:00. Between those commands cat 2.txt was blocked with "permission denied" because read was removed (mode 000), which confirmed the permission effect while stat confirmed only ctime ticked.

Example 3 — Content change advances mtime and ctime together. Starting from a blocked state, restoring with chmod 666 2.txt (ctime ticks), then appending with echo "added to the last" >> 2.txt and running stat 2.txt showed Modify: 2024-05-20 12:08:15 and Change: 2024-05-20 12:08:15 equal to the second. A subsequent cat 2.txt moved Access: 12:08:17 alone. The pairing mtime == ctime after a write is the signature of a content edit.

Example 4 — Comparing listing variants. Running ls -l 2.txt (shows May 20 12:08 — the mtime), ls -lc 2.txt (shows May 20 12:08 — the ctime after the last chmod or write, often a few seconds later) and ls -lu 2.txt (shows May 20 12:08 or slightly later after the last cat) side by side showed three different dates for the same inode. stat then displayed all three together and proved that the ls date column is simply a lens onto one clock at a time.

5.7.5 Student Questions and Answers

Q: If I change the file's name, does the inode number change? A: No. Renaming with mv 2.txt newname.txt changes the directory entry, not the inode allocation. stat after the mv still reports the same Inode: number. Likewise, chmod changes the permission field inside the inode and advances ctime without allocating a new inode. Only a new creation (touch new, cp, mkdir) allocates a new number. The directory's own ctime and mtime do tick on rename.

Q: Which timestamp shows the last time the file was opened for reading? A: That is atime, shown by ls -lu and by the Access: line of stat. mtime shows the last content edit (default ls -l, Modify:) and ctime shows the last metadata change (ls -lc, Change:). The memory hook is u for use equals access, c for card change.

Q: Are ls -lc and ls -lu interchangeable? A: No. ls -lc shows inode change time; ls -lu shows access time. The session corrected an earlier swap and noted this exact pairing: c with change, u with access. Mixing them is a frequent exam trap — write the pairing down as lc = last changed, lu = last used.

Pitfalls — clocks: 1) Calling ctime creation time — it is change time and cannot be faked with touch; touch sets atime/mtime only. 2) Waiting for atime on every cat — modern relatime may delay it; rely on stat before and after a controlled write. 3) Thinking mv must bump mtime — within one file system it does not; timestamps follow the inode, not the name. 4) Reading ls -l as creation — it is modify.

Recap — who winds which clock: Read winds atime (ls -lu), write winds mtime (ls -l) and ctime together (ls -lc), permission or count change winds ctime alone, rename keeps the same inode. Check with stat: three lines, three clocks, one card number. The next section uses those same counters to explain links.

5.9 Practice Worksheets and Submission

Hook — from lecture to proof: The session closed by turning the concepts you can now read — inode, ls -li, rwx, chmod, stat clocks and links — into worksheets that ask you to capture the listing that proves you did each step. One aggregated text file carries that proof to the portal.

The session closed with structured hands-on work intended to reinforce inodes, permissions, links and timestamps. The task was to capture terminal output into a single text file and submit it through the course portal. Worksheets were designed to be completed over the week; each asks for before and after evidence so gaps are visible.

5.9.1 Worksheet Tasks

What each worksheet checks: Worksheet 1 proves you can tell a hard link by its shared inode and converged edits. Worksheet 2 proves you can tell a symbolic link by its separate inode, l and path-sized size. Worksheet 3 proves you can follow a soft link through edits and spot when the link follows the source.

Worksheet 1 — Hard link with info.txt.

  1. Create info.txt with the content "This is info." — verify with cat info.txt.
  2. Record its inode number (ls -i info.txt) and its link count (second column of ls -l info.txt or stat info.txt Links: line). Expect Links: 1 and size equal to the text length plus newline.
  3. Create a hard link with ln info.txt info_hard.txt (or ln info.txt bits/info_hard.txt variant) and record the link's inode number (ls -li info.txt info_hard.txt shows the same number twice), file type character (-, not l), content (cat info_hard.txt matches info.txt), and whether editing one name changes what the other sees. Demonstrate with cat >> info.txt adding a line such as added via hard and then cat info_hard.txt — the new line must appear.
  4. Note the link count increment before (1) and after creation (2) and after removal with rm info_hard.txt back to 1. stat before and after proves the count and shared inode.

Worksheet 2 — Symbolic link. Repeat a parallel study for a symbolic link:

  1. Create the same source info.txt (restore if you removed it) and note its current size.
  2. Create a symbolic link with ln -s info.txt info_soft.txt (use a distinct name to avoid collision).
  3. Record the link's inode number (ls -li info.txt info_soft.txt shows two different numbers), file type l with info_soft.txt -> info.txt and colour highlight, size difference (link size is length of info.txt path, e.g., 8, versus source size e.g., 14), and content as seen through the link (cat info_soft.txt shows the source text because lookup follows the path). Change content via the source with echo "soft follows" >> info.txt and show whether cat info_soft.txt follows the change — it must.
  4. Observe and note the link count behaviour: stat info.txt Links: stays 1 (symbolic links do not increment the source count); stat info_soft.txt shows Links: 1 for the link's own name.

Worksheet 3 — Old and old_soft.

  1. Create old.txt and a symbolic link old_soft.txt pointing to it (touch old.txt; ln -s old.txt old_soft.txt).
  2. Add content to old.txt with echo "first" > old.txt, then inspect both names (cat old.txt; cat old_soft.txt — same content). Then append via the link target or through the link as specified in the handout (echo "via soft" >> old_soft.txt follows to the source on most writes). After each command cat old.txt and cat old_soft.txt should match while the link exists.
  3. Report the content of old.txt and old_soft.txt after each step, plus ls -li old.txt old_soft.txt to show two inodes but converged content, to make clear when the link follows the source and when it holds its own path string.

Ancillary exercises repeated throughout the session included:

  • touch 1.txt then ls -l to note default rw-rw-r-- and which umask produced it.
  • chmod 000, 700, 760, 741, 666, 774 variations on the same file with ls -l verification after each, noting which operation was idempotent.
  • stat 2.txt series capturing access, modify and change times after cat, chmod and echo >> to tick each clock once, then ls -lc/ls -lu side by side to confirm the three lenses.
  • ls -li /dev > output.txt to create a persistent snapshot of the device directory for review of c versus b and small inode numbers.

Capture trace you can copy — one pattern for all sheets: After each command, capture the proof in the same way:

ls -li info.txt info_hard.txt
# 3277400 -rw-rw-r-- 2 alice alice 14 May 20 12:10 info.txt
# 3277400 -rw-rw-r-- 2 alice alice 14 May 20 12:10 info_hard.txt
stat info.txt
# Inode: 3277400  Links: 2  Access: ... Modify: ... Change: ...
cat info.txt
# This is info.
cat info_hard.txt
# This is info.

Repeat with info_soft.txt and note the two inodes and lrwxrwxrwx plus ->. At the end cat output.txt from ls -li /dev > output.txt shows the device snapshot.

5.9.2 What to Capture and Submit

Single file, full trace: Every worksheet ends with the same submission artifact: one text file that contains the before and after lines so a reviewer can see the shared inode for hard links, separate inodes for soft links, rwx before and after each chmod, and stat before and after each cat/chmod/echo tick. The session noted > as the mechanism to build that file step by step.

The expectation announced was to copy the command output from all worksheets into one text file. The file should contain:

  • The inode (ls -i) and link count (ls -l second column or stat Links:) answers for each source and link before and after each creation and removal.
  • The post-chmod listings (ls -l) that show how each octal (000, 700, 760, 741, 666, 774) or symbolic (u+rwx, g+r, o+x, a+rwx) mode changed the ten-character string, with the octal or symbolic input echoed alongside.
  • The stat and ls -lc/ls -lu outputs that demonstrate which timestamp moved and which stayed after cat (atime), chmod (ctime), and append (mtime and ctime).
  • The cat outputs before and after edits that prove hard-linked names converge and symbolic links either follow or go red and dangling when the source is removed.

Practical capture method used in the session: run command >> submission.txt 2>&1 to append each command's output, or start with ls -li /dev > output.txt for the device snapshot and then cat output.txt >> submission.txt. Verify the final file with cat submission.txt before upload.

That aggregated file was to be uploaded via the assignment link created on the portal for this third session. The session noted that the worksheets can be worked on through the week and submitted by the date announced for this session. Late guidance was to keep the link names distinct (info_hard.txt and info_soft.txt versus reusing info.txt) so the l versus - and shared versus distinct inode remain legible in the captured ls -li.

Pitfalls — worksheets: 1) Capturing only the final state — keep before and after ls -li and stat around each ln and rm. 2) Forgetting to show the type character — include ls -l so l and arrow are visible for symlinks. 3) Mixing > and overwriting earlier work — use >> after the first capture. 4) Naming the symlink the same as the source in the same directory without a path — use old_soft.txt so ls -li is unambiguous.

Recap — proof completes the loop: Worksheets 1–3 turn "inode is the card, name is the label" into a captured line you can point at: same number and Links: 2 for hard links, different numbers and l -> target for soft links, rwx ticks that move with chmod, and clocks that tick with cat versus chmod versus >>. Bundle those captures into one file and the portal submission is the grade-bearing artifact.

Exam Guidance Summary

Exam note — what the session drilled as testable, even though no formal mark split was announced: Treat the points below as the review checklist the live practice implied. Each is tied to a command and output you already captured in worksheets.

No formal mark distribution or question paper pattern was announced in the captured session. The following examination-relevant guidance emerged from what was practiced and flagged as important:

  • Expect to decode and produce ten-character ls -l strings — identify file type from position one (-, d, c, b, l, p, s) and read, write, execute rights for user, group and others. Tasks such as "find the permission of student.doc" and predicting output after chmod fall in this group. Reading method: count to ten, split type | rwx | rwx | rwx, then pick the triplet by owner/group/others.
  • Expect to translate between permission triplets and three-digit octal modes in both directions, including specific conversions that were drilled: (----------), (rwx------), (rwxrw----), (rwxr----x), (rw-rw-rw-), (rw-rw-r--) and (rwxrwxr--). Knowing that , , and that each digit is - (computed as ) is essential. The binary table through is worth memorizing.
  • Expect to use both absolute and relative chmod forms: absolute as three octal digits that overwrite all nine bits, relative as plus or plus that modifies incrementally (e.g., chmod u+rwx, chmod g+r, chmod o+x, chmod a-rwx, chmod ugo+r). Exam note: the slide explicitly contrasted "has to be in octal decimal numbers only" and rejected binary strings like 110 as invalid mode — write three digits 07, not a binary literal.
  • Expect questions on ls options: -i for inode number, -l for long listing, -li combined (inode as first column), -lc for change time (ctime), -lu for access time (atime). A corrected pairing to remember is that ls -lc shows inode change time and ls -lu shows access time — the session swapped them early and then corrected to c = change, u = access.
  • Expect to differentiate the three timestamps — atime (access, ls -lu, stat Access:), mtime (content change, default ls -l, stat Modify:) and ctime (inode change, ls -lc, stat Change:) — and to say which operation advances which stamp (read with cat advances atime; content edit with echo >> advances mtime and ctime together; permission or ownership change with chmod/chown advances ctime alone; rename with mv inside one file system leaves the file's inode number and mtime unchanged). The file's ctime after a write matches mtime.
  • Expect hard and soft link distinctions: hard links share the same inode and increment link count, cannot be made for directories and cannot cross file systems; symbolic links have a different inode, show l and name -> target, size equals path length, can point to directories and across file systems, and become dangling when the source is removed. Commands ln source target versus ln -s source target and removal with rm linkname are testable.
  • Expect output capture via redirection > as in ls -li /dev > output.txt versus append >>, and that the resulting output.txt is a regular file - holding the snapshot of a mixed c/b/l device listing.
  • Study advice implicit in the session: practice each chmod table row until you can move between binary (e.g., 110), octal - (e.g., 6), and displayed string (rw-) without a reference; then drill the worksheet trace ls -listatcatstat around every link and permission step.

Exam note — quick self-check before you leave: Can you write rwxr----x as 741 and 741 as rwxr----x from memory, add x for group without recomputing (chmod g+x file), state which of ls -lc and ls -lu shows which clock, and predict whether rm source leaves hard_link readable but soft_link dangling? If yes, the session's testable core is covered.

Key Industry Applications

Where the session's primitives surface in production: The inode, type, permission, timestamp and link machinery is not lab trivia — it is the same interface containers, build systems and backups depend on.

  • Unified file system interface to hardware. Real-world: listing /dev shows character devices such as terminals (tty, console, pty) and serial or parallel ports (c) and block devices such as hard disks sda, sda1, loop devices (b) through the same directory model as regular files. Systems code, drivers, udev and containers all rely on this uniformity — opening /dev/null or mounting a volume uses the same open path as opening a document, with type and permission bits deciding who may talk to the device.
  • Inter-process communication objects. Real-world: named pipes (p, FIFO created with mkfifo) and Unix domain sockets (s in /run, /tmp) appear as file system entries where used, enabling pipelines (producer | consumer), systemd sockets and local service sockets. Pipes and sockets along with shared memory are the canonical IPC techniques named alongside networking courses; choosing a p file versus a s file decides whether the channel is a byte stream or a datagram socket.
  • Shortcuts, versions and library aliases. Real-world: symbolic links (l, Windows shortcut analogy) provide version-independent names for libraries (libfoo.so -> libfoo.so.2.1), shared datasets (data -> /mnt/shared/dataset) and deployed binaries (python -> python3). Hard links provide storage-efficient deduplication where one file system hosts the same large object under several project paths, such as rsync --link-dest snapshots where unchanged files are hard-linked across daily snapshots.
  • Ownership and collaboration. Real-world: the owner, group and others columns drive team workflows. A project directory can be assigned to a group (chown :team project; chmod 770 project), private files kept at rw------- or rw-r----- , and shared deliverables opened to rw-rw-r-- or rw-rw---- . Teams routinely start from 664 for data and 755 (rwxr-xr-x) for directories and scripts, then refine with chmod g+rw or o-r so the semester project passes permissions review on a shared lab machine.
  • Auditing with timestamps and inodes. Real-world: stat output, ls -lc and ls -lu support debugging and compliance — forensics compares mtime versus ctime to tell a content edit from a permission change, build systems like make compare mtime to decide what to recompile, and backups decide what changed by comparing ctime versus last backup while avoiding atime churn.
  • Redirection and snapshots. Real-world: > output.txt is the primitive behind logging, capturing listings like ls -li /dev into artifacts that can be archived, diffed or submitted through a portal, as required for this session's worksheets. Production scripts chain ls -liR >> log.txt or find . -printf "%i %p\n" >> manifest.txt to create inode-aware manifests that detect duplicates without copying.

Takeaway — cards, uniforms, keys, clocks and arrows: The kernel tracks identity by inode number, family by type character, access by nine rwx keys, history by three clocks and sharing by hard versus symbolic arrows. Read ls -li and stat first, change with chmod 4-2-1 or u/g/o +/- rwx, and confirm sharing with matching versus distinct inodes — that workflow carries from lab worksheets to production systems.

SP Lecture 5 notes · Linux File System — Inodes, File Types, Permissions and Links

Systems Programming· postgraduate· 2026-08-20

Sections Breakdown

1Inodes and File Identity

Inode numbers, the name-to-inode-to-metadata mapping, ls -i and ls -li, and allocating new inodes with mkdir and touch

2The Long Listing — What Every Column Means

Reading ls -l and ls -li columns, the ten-character type and permission field, owner, group, size and timestamps

3File Types — The First Character

Interpreting - d c b l p s, character versus block devices in /dev and capturing output with redirection

4File Permissions — rwx for User, Group and Others

Meaning of r, w and x for files and directories, the three triplets and who may read, write or execute

5Changing Permissions — Absolute (Octal) Mode

chmod with three octal digits, the 4-2-1 mapping and worked conversions 000, 700, 760, 741, 664 and 774

6Changing Permissions — Relative (Symbolic) Mode

Symbolic chmod with categories u g o a and operations + -, incremental builds and idempotence

7File Timestamps — Access, Modify and Change

atime, mtime and ctime, viewing with stat, ls -lc and ls -lu and how operations move each stamp

8Links — Hard Links and Symbolic Links

ln versus ln -s, shared inode and link count, dangling symlinks and limits on directories and file systems

9Practice Worksheets and Submission

Hands-on tasks to prove hard and soft links, chmod translations and timestamp clocks with captured output

10Exam Guidance Summary

Distilled testable checklist: ten-character decode, octal translations, timestamp flags and link differences

11Key Industry Applications

Where file types, permissions and links appear in production: /dev, IPC, version aliases and auditing

Postgraduate students in Systems Programming

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Inodes and File Identity

Must-know: Inode is unique per file system; ls -i shows it, ls -li adds it to long listing; new name gets new inode, rename does not

⚠️ Top pitfall: Thinking mv creates a new inode within one filesystem; it only changes the directory entry

Self-check: What does ls -i add to ls -l output and what does mkdir -p do?

Connects to: 5.2, 5.7, 5.8

The Long Listing — What Every Column Means

Must-know: Ten-char field is 1 type + 9 rwx bits as user group others; directory size 4096 is structure size

⚠️ Top pitfall: Mixing dash for regular file in position 1 with dash for missing rwx in positions 2-10

Self-check: Split -rwxr--r-- into type and three triplets and state who may cat

Connects to: 5.1, 5.3, 5.4

File Types — The First Character

Must-know: c streams chars (tty, console) vs b blocks (sda); l shows arrow and separate inode; p/s appear where created not in /dev

⚠️ Top pitfall: Expecting cat to decide type; both text and binary share -; p/s absent in /dev is normal

Self-check: What type char does /dev/sda show and how to capture ls -li /dev into file?

Connects to: 5.2, 5.8

File Permissions — rwx for User, Group and Others

Must-know: Kernel picks exactly one triplet by matching owner then group then others; dash in x slot means no execute

⚠️ Top pitfall: Thinking triplets add together; they are exclusive and directory x means traverse not run

Self-check: For -rw-rw-r-- who may write and who may only read?

Connects to: 5.2, 5.5, 5.6

Changing Permissions — Absolute (Octal) Mode

Must-know: Absolute overwrites all nine bits; 664 is rw-rw-r-- default, 741 is rwxr----x; binary 110 is 6 not a chmod digit

⚠️ Top pitfall: Typing binary 110 as one octal digit; must convert each rwx triplet to 0-7 first

Self-check: Convert rwx r-- --x to octal and back

Connects to: 5.4, 5.6

Changing Permissions — Relative (Symbolic) Mode

Must-know: Relative modifies only named categories; ugo+r same as a+r and + is idempotent

⚠️ Top pitfall: Using = when + was meant; g=r clears w/x for that group

Self-check: How to add execute for group without recomputing user and others?

Connects to: 5.4, 5.5

File Timestamps — Access, Modify and Change

Must-know: cat ticks atime, chmod ticks ctime only, write ticks mtime and ctime together, mv keeps same inode

⚠️ Top pitfall: Calling ctime creation time; it is inode change and cannot be set with touch

Self-check: Which ls option shows atime and which shows ctime?

Connects to: 5.1, 5.2, 5.8

Links — Hard Links and Symbolic Links

Must-know: Hard same inode count+ no l cannot cross FS or dir; soft different inode l arrow can cross and may break; rm removes name not data

⚠️ Top pitfall: Reading hard link as l; hard keeps - and shared inode is the proof

Self-check: After rm source does hard survivor still cat and does soft?

Connects to: 5.1, 5.7

Practice Worksheets and Submission

Must-know: Capture inode and Links before and after ln/rm; include ls -l for type and rwx ticks

⚠️ Top pitfall: Overwriting submission.txt with > instead of appending with >>

Self-check: What must one submission file contain for each worksheet?

Connects to: 5.1, 5.5, 5.7, 5.8

Exam Guidance Summary

Must-know: Review ls -l decode, 000-774 conversions, ls clocks and link table

⚠️ Top pitfall: Swapping ls -lc and ls -lu

Self-check: Write 741 as rwx and name which ls flag shows ctime

Connects to: 5.2, 5.5, 5.7, 5.8

Key Industry Applications

Must-know: Where rwx and links appear in production systems

⚠️ Top pitfall: Thinking redirection is only for lab; it builds production logs

Self-check: Name one production use for symlink and one for hard link

Connects to: 5.3, 5.4, 5.8

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.