Skip to content

Module 0.4: Files and Directories

Complexity: [MEDIUM] - Long-form foundational read for absolute beginners

Time to Complete: 90–120 minutes (long-form beginner read + practice)

Prerequisites: Module 0.3: First Terminal Commands — You should be able to open a terminal, run commands such as echo, pwd, mkdir, and touch, and read their output. Module 0.3 builds on Module 0.2: What is a Terminal?, so complete both before starting here.


After this module, you will be able to:

  • Navigate absolute and relative paths and choose the safer form for a command, script, or troubleshooting session.
  • Read files with cat, head, and tail, then select the command that fits the size and purpose of the file.
  • Interpret file permissions from ls -l output and diagnose who can read, write, or enter a file or directory.
  • Find hidden dotfiles and explain what a leading dot does and does not protect.

When a command reports a file path, you need to know where it starts, how to inspect the file, and whether your account can reach it. These skills apply to notes and project files as well as system logs.

Paths identify files and directories. For example, tail -n 20 /var/log/syslog asks for the last twenty lines of a file at an absolute path, if that file exists and you can read it.

This module gives you that map-reading skill. You will learn what files and directories are, how Linux arranges them in a tree, how to move with pwd, ls, and cd, how to decide between absolute and relative paths, how to inspect file contents, how to spot hidden dotfiles, and how to read the first permission characters that appear in ls -l. The goal is not memorizing commands in isolation. The goal is being able to look at a path during a real troubleshooting task and know what to try next.

Files, Directories, and the Tree Under Every Command

Section titled “Files, Directories, and the Tree Under Every Command”

A file is a named container for information stored on your computer. It can hold a grocery list, a shell script, a Kubernetes manifest, a photo, a database page, or a log entry written by a running service. The important beginner idea is that the name is not the whole identity of the file; a file also has contents, a location, ownership, permissions, and timestamps that tell the operating system how the file may be used.

Think of a file like a recipe card in a working kitchen. The card has a name, such as grocery-list.txt; it has contents, such as “eggs, milk, bread”; and it sits in a location, such as a drawer or recipe box. If two drawers both contain a card named sauce.txt, the name alone is not enough. You need the location as well, which is why paths matter so much in terminal work.

Files can contain many kinds of data. A text file might contain notes, source code, a YAML manifest, or shell commands. A binary file might contain an image, a compiled program, compressed data, or a database. The commands below use small text files that you create for practice.

Linux also exposes some system interfaces through paths. Entries such as /dev/null are device special files; /proc is a pseudo-filesystem exposing process and system information. They are not ordinary stored documents. You do not need to manage them here, but recognizing those paths will help you read later troubleshooting examples.

/ <-- The "root" — the very top, the ground floor
├── home/ <-- Where user accounts live
│ └── yourname/ <-- YOUR home directory
│ ├── Documents/
│ ├── Downloads/
│ ├── Desktop/
│ └── projects/
├── etc/ <-- System configuration files
├── var/ <-- Variable data (logs, databases)
├── tmp/ <-- Temporary files
└── usr/ <-- User programs and utilities

A directory contains entries for files and other directories. A graphical interface often calls it a folder; paths express the relationships between those entries.

The tree starts at /, called the root directory. Every absolute path begins there, even if the directory you use every day is much lower in the tree. Home directories commonly live under /home/ on Linux and /Users/ on macOS. System configuration often lives under /etc/, logs under /var/log/, and temporary files under /tmp/. For a Kubernetes example, kubeadm writes static Pod manifests under /etc/kubernetes/manifests/; kubectl uses ~/.kube/config by default. These are illustrative locations, not directories you need to create for this lesson.

PathWhat It IsKitchen Analogy
/Root directory — the very top of the treeThe building itself — everything is inside it
/home/yourname/Your home directory — your personal spaceYour personal workstation in the kitchen
~Shorthand for your home directoryA nickname for your workstation
/etc/System configuration filesThe restaurant’s policy manual and recipe standards
/tmp/Temporary files that may be cleaned automatically depending on system policyThe prep table — used during cooking, sometimes cleaned up automatically
/var/log/Log files, or records of what happenedThe order history book

The ~ character is a shell shortcut for your home directory, not a directory named tilde that you normally see in ls. That distinction matters when you read documentation. A command that points to ~/.kube/config means “inside the current user’s home directory, find a hidden .kube directory, then read the config file.” It does not matter whether the user’s actual home path is /home/amina, /home/yourname, or /Users/amina on macOS.

Pause and predict: if two users on the same Linux machine both read ~/.kube/config, do they read the same file or different files?

Check your prediction

They usually read different files, because ~ expands separately for each user’s shell session. One user’s ~/.kube/config might resolve to /home/amina/.kube/config while another’s resolves to /home/yourname/.kube/config, even though both typed the identical command. That is why documentation uses ~ for personal configuration but uses absolute system paths, such as /etc/kubernetes/manifests/, for machine-wide configuration.

ConceptBeginner MeaningOperational Consequence
FileNamed data stored by the systemLogs, manifests, scripts, and notes can all be inspected with terminal tools
DirectoryContainer for files or directoriesPaths work because every item has a parent location
Root /Start of the whole filesystem treeAbsolute paths can locate a file from anywhere
Home ~Current user’s personal directoryPersonal config such as shell settings and kubeconfig stays user-specific
DotfileHidden file or directory whose name starts with .Important configuration may not appear in plain ls output

Your shell has a working directory. To navigate, ask where you are, what is there, and where you want to go.

The first question is answered by pwd, which stands for print working directory. It gives you the full absolute path to your current location. In the kitchen analogy, pwd is the answer to “which room am I standing in right now?”, and that answer determines whether relative directions such as Documents/report.txt make sense.

Terminal window
pwd
/home/yourname

The second question is answered by ls, which lists directory contents. With no path, it lists the current directory; with a path, it lists that location instead.

Terminal window
ls

Sample output; yours will differ:

Desktop Documents notes.txt

The -l option asks for long format, which includes file type, permissions, owner, group, size, timestamp, and name. You do not need to understand every column immediately, but the first column is worth recognizing early because it tells you whether an entry is a file or directory and who can use it. Later in this module, you will decode strings such as drwxr-xr-x and -rw-r--r--.

Terminal window
ls -l
drwxr-xr-x 2 yourname yourname 4096 Mar 23 10:00 Desktop
drwxr-xr-x 3 yourname yourname 4096 Mar 23 09:45 Documents
-rw-r--r-- 1 yourname yourname 220 Mar 23 08:30 notes.txt

The third navigation command is cd, which changes your working directory. You give it a destination, and the shell moves your session there if the destination exists and you have permission to enter it. Unlike opening a folder in a graphical interface, cd does not print a success message by default. That silence is normal, which is why many learners pair cd with pwd while building confidence.

From your home directory (when a Documents folder exists there):

Terminal window
cd Documents
pwd
/home/yourname/Documents
CommandWhere It Takes YouAnalogy
cd ~ or just cdYour home directory“Go back to my workstation”
cd ..One level up, the parent directory“Go to the room that contains this room”
cd -The last directory you were in“Go back to where I just was”
cd /The root directory“Go to the ground floor”

Use cd - to return to the previous directory. The next example ends at /; the workspace setup will return you home before creating files.

Terminal window
cd /
pwd

Before running this, predict what the last pwd will print after cd /, then compare it with the output.

Check your prediction

The last pwd prints /, the root directory, because cd / moves you to the very top of the filesystem tree. An absolute destination like / always lands in the same place, no matter where your session was standing before the command. If your run printed something else, re-check the order of the commands rather than blaming the shell.

A path is a written route to a file or directory. There are two kinds you will use constantly: absolute paths and relative paths. The difference is not academic; it decides whether a command works from anywhere or only from a particular starting directory.

An absolute path starts at the root directory / and gives the complete location. It is like a full street address: the address works no matter where you are standing when you read it. If a troubleshooting guide says to inspect /var/log/syslog, you can run that command from your home directory, from /tmp, or from a project directory, and the path still points to the same file.

/home/yourname/Documents/report.txt

A relative path starts from your current working directory. It is like saying “two rooms down, then left”; the directions are shorter, but they depend on where you begin. Relative paths are excellent inside a project because they keep commands concise, but they are risky in scripts when the script might be launched from different places.

Documents/report.txt

Here is the same destination reached in two different ways. The absolute path names the whole route from /, while the relative path works only because the shell is already in /home/yourname. If your current working directory were /tmp, cd Documents would look for /tmp/Documents, not /home/yourname/Documents.

Terminal window
pwd
/home/yourname

Example paths — adjust yourname and directory names to match your machine:

cd /home/yourname/Documents
cd Documents
SymbolMeaningExample
/Root directory at the start, or path separator between names/home/yourname
~Your home directory~/Documents means /home/yourname/Documents on many Linux systems
.Current directory, or “here”./script.sh means script.sh in this directory
..Parent directory, or “up one level”../Downloads means go up, then into Downloads

The . symbol identifies the current directory. ./script.sh names a script there explicitly. A command name without a slash instead goes through the shell’s command-search rules; being in the directory alone does not ensure that the shell will find the program.

The .. symbol is the cleanest way to move to a sibling location. If you are in /home/user/projects/app/src and need /home/user/projects/app/README.md, the relative path ../README.md says “go to the parent directory, then read README.” That is shorter than the absolute path and still precise because you know your current location.

Example relative path (run only when your current directory is a child of the folder that contains README.md):

cat ../README.md

Which approach would you choose here and why: an absolute path to /home/user/projects/app/README.md, or the relative path ../README.md? Commit to an answer before opening the reveal.

Check your prediction

In an interactive project session, the relative path is usually faster and clearer. In an automation script that might run from several directories, the absolute path or a path derived from the script’s own location is usually safer. The deciding question is whether the starting directory is stable and known, not which form looks shorter on the screen.

SituationPreferWhy
Reading a known system logAbsolute pathThe file has a stable machine-wide location
Moving inside one project treeRelative pathShorter commands reduce noise while context is clear
Writing a script for other usersAbsolute or derived pathThe script should not depend on the caller’s current directory
Referring to personal configuration~ pathThe path adapts to each user’s home directory
Explaining a filesystem conceptBoth formsComparing them builds the learner’s mental map

Reading Files Without Flooding Your Terminal

Section titled “Reading Files Without Flooding Your Terminal”

Once you can point to a file, the next skill is choosing how to read it. The beginner temptation is to use one command for everything, but file-reading tools are shaped by file size and purpose. A short note, a long generated report, and a constantly growing log file deserve different commands.

cat displays the whole file. Its name comes from “concatenate” because it can join files together, but learners usually meet it first as a way to print a file to the terminal. It is excellent for small files where seeing the entire content is useful, such as a short note, a one-screen configuration snippet, or a tiny example manifest.

Example (create notes.txt first, or use any small file you already have):

cat notes.txt
This is my first note.
I wrote it in the terminal!

The tradeoff is that cat does not protect you from enormous output. If a log file has hundreds of thousands of lines, printing all of it can make your terminal hard to use and hide the recent lines you wanted. That is why experienced engineers ask a second question before reading: do I need the whole file, the beginning, or the end?

head shows the beginning of a file, ten lines by default. It is useful when the top of a file contains headers, metadata, comments, or the first entries in a report. You can change the number of lines with -n, which makes the command predictable and gentle even when the file is large.

head long-file.txt
head -n 5 long-file.txt

tail shows the end of a file, also ten lines by default. This is one of the most important log-reading habits because many logs append new entries at the bottom. If a service crashed recently, the newest error is more likely near the end than near the top.

tail log-file.txt
tail -n 20 log-file.txt

Think about it: you need to check the last few lines of a log file that is 10,000 lines long. Would you use a command that shows the whole file, or one that shows just the end? Commit to an answer before opening the reveal.

Check your prediction

tail is designed for this situation because it lets you focus on the newest events without scrolling through everything that happened earlier. Printing all 10,000 lines with cat would bury the few recent lines you actually need and make your terminal hard to use in the process.

ToolBest ForAvoid WhenExample Use
catSmall files where the whole content mattersLarge logs or generated outputRead a short note or tiny config file
headFile headers, first records, initial commentsRecent log errors near the bottomCheck the first lines of a CSV or report
tailRecent log events and appended filesUnderstanding the full structure of a fileInspect the newest system log lines

For logs, tail can limit output to the latest lines. Configuration and logs may contain sensitive data: use sanitized examples for practice and inspect only what you need, without sharing private output. The kubeconfig metadata example below is illustrative; it is not required for this lesson.

Illustrative log path — use this only on a machine where that log exists and you may read it:

tail -n 20 /var/log/syslog
ls -l ~/.kube/config

The second command checks that the file exists and shows its permissions without printing tokens or certificates. Many configuration files contain tokens, certificates, usernames, or cluster endpoints. When the file may include secrets, prefer reading only the part you need, avoid pasting output into chat systems, and consider whether a safer inspection command exists.

Creating Directories, Files, and Hidden Configuration

Section titled “Creating Directories, Files, and Hidden Configuration”

Navigation becomes more useful when you can create a small structure of your own. mkdir creates directories, and touch creates an empty file if it does not already exist. These commands are simple, but the distinction matters: applications that expect a directory cannot write logs into a regular file, and scripts that expect a file cannot read useful content from an empty directory.

The earlier navigation ended at /; do not create practice files there. You can use the Ubuntu playground for the self-checked exercises. If its terminal starts as root, run su - ubuntu to use the existing unprivileged account. For every file-changing example below, use a new directory that you create solely for this lesson and keep under your exclusive control. Being inside your home directory alone does not make existing files disposable.

A symbolic link is a file that points to another path. Run these commands one line at a time. After any mkdir or cd error, stop: do not run the next line or any file-writing command. If mkdir reports that the name exists (including a file or symbolic link), leave it untouched, choose an unused name such as kubedojo-practice-2, and substitute that name in every later project path. Do not use mkdir -p for this workspace root: it would accept an existing directory instead of establishing a fresh one.

Terminal window
cd ~
mkdir kubedojo-practice
cd kubedojo-practice
pwd
ls -a

Continue only when pwd identifies the directory you just created and ls -a shows only . and ... Keep this terminal in the workspace through the examples and hands-on tasks. If you lose track of its ownership or contents, stop and create a new workspace using the same procedure; do not reuse an unfamiliar directory or delete it to make the instructions work.

Terminal window
mkdir recipes

The mkdir command creates one directory at the path you provide. If the parent directory exists and you have permission to write there, the command succeeds silently. If the parent path does not exist, plain mkdir fails because it does not invent the missing middle of the tree unless you ask it to.

Terminal window
mkdir -p recipes/italian/pasta

The -p option means “create parent directories as needed.” Within this owned workspace, it lets you extend the tree even when part of the structure already exists; it does not prove an existing directory is safe to reuse. Without -p, creating recipes/italian/pasta would fail if recipes/ or recipes/italian/ had not been created first.

Terminal window
touch shopping-list.txt

touch creates a new empty file, but it also updates the timestamp when the file already exists. That dual behavior is useful, but it can surprise beginners. If you expected touch to add content, nothing will appear inside the file; it is more like placing a blank recipe card on the counter than writing the recipe.

Names beginning with a dot do not appear in a plain ls listing. In your owned workspace, create a disposable example, then compare the listings:

Terminal window
touch .practice-hidden
ls
recipes shopping-list.txt
Terminal window
ls -a
. .. .practice-hidden recipes shopping-list.txt

Some tools use dot-prefixed names for configuration; kubectl’s default ~/.kube/config is one example. You can recognize such paths without opening real credentials for this exercise.

Hidden does not mean secret. A dotfile is hidden from default directory listings, but any user with enough filesystem permission can still read it. This distinction matters for files such as .env, .ssh/config, or ~/.kube/config, because naming a file with a leading dot does not protect credentials. Protection comes from permissions, careful sharing, and not printing sensitive content where it does not belong.

Pause and predict: if plain ls does not show .practice-hidden, can you address it directly when you have permission?

Check your prediction

Yes, if the file exists and you have access: the leading dot affects the default listing, not the name used in the path. Addressing the file directly does not depend on whether plain ls displayed it.

Try ls -l .practice-hidden in your workspace to inspect the entry directly.

File permissions are how Unix-like systems express who can do what. At this stage, you only need to read the permission string, not change it. That skill is enough to diagnose many beginner errors: “permission denied” when entering a directory, a script that cannot run, or a sensitive file that is readable by more people than intended.

drwxr-xr-x 2 yourname yourname 4096 Mar 23 10:00 Desktop
-rw-r--r-- 1 yourname yourname 220 Mar 23 08:30 notes.txt

The first character tells you the type of entry. A d means directory, while - means a regular file. The next nine characters come in three groups of three: permissions for the owner, permissions for the group, and permissions for everyone else. Each group uses r for read, w for write, x for execute or directory entry, and - when that permission is absent. Run id to see the current process’s user and group information, then compare its groups with the group shown by ls -l.

- rw- r-- r--
| | | |
| | | └── Others (everyone else) permissions
| | └── Group permissions
| └── Owner account permissions
└── File type (- = file, d = directory)
LetterPermissionFor FilesFor Directories
rReadCan see the contentsCan list what’s inside
wWriteCan change the contentsCan add or remove entries when x also permits traversal
xExecuteCan run it as a programCan enter the directory with cd
-No permissionCannot do that actionCannot do that action

The directory behavior is the part many beginners miss. Execute on a file means “can run it as a program,” but execute on a directory means “can enter or traverse it.” A directory may be readable but not enterable, or enterable but not listable, depending on the exact bits. Adding or removing names normally needs both w and x on the containing directory. Other restrictions can still block an operation; the Linux file-creation and file-removal error lists distinguish these checks.

-rw-r--r-- notes.txt

In this example, the first - says notes.txt is a regular file. The owner segment rw- means the owner can read and write but not execute it as a program. The group segment r-- means group members can read but not write. The others segment r-- means everyone else with access to the path can also read it.

drwxr-xr-x Desktop

In this directory example, d says the entry is a directory. The owner has rwx, so the owner can list it, add or remove entries, and enter it. Group and others have r-x, so they can list and enter it but cannot add or remove files there. This is a common shape for directories that should be visible but not writable by everyone.

Permission StringPlain-English ReadingCommon Interpretation
-rw-r--r--Owner can read and write; group and others can readNormal non-secret text file
-rw-------Owner can read and write; group and others have no ordinary access permissionsSensitive personal file
drwxr-xr-xOwner controls directory; others can list and enterCommon user-visible directory
drwx------Owner alone can list, write, and enterPrivate directory such as some key stores
-rwxr-xr-xOwner can run and edit; others can run and readExecutable script or program

Permissions are like keys in the kitchen. The head chef may have the key to open, edit, and reorganize every drawer. A sous-chef may be allowed to read the recipe cards but not replace them. Visitors may be allowed to see a posted menu but not enter the storage room. The permission string compresses that policy into a short form you can read quickly during troubleshooting.

These examples describe ordinary permission bits, not an absolute privacy guarantee. On Linux, privileged capabilities can bypass some access checks. Keep that distinction when reading a private-looking mode: it describes normal file access, not encryption or protection from an authorized administrator. Shared machines can also have additional access rules that need separate inspection.

The appetizer directory is created in the hands-on exercise; this first listing is illustrative until then:

ls -l recipes/appetizers/
Terminal window
ls -ld recipes

The -d option in the second command is worth noticing. Without it, ls -l recipes lists the contents of the recipes directory. With -d, it lists the directory entry itself, including permissions on the directory. When diagnosing why you cannot enter or write to a directory, ls -ld is often the clearer command.

Worked Example: Trace the Path Before You Touch the File

Section titled “Worked Example: Trace the Path Before You Touch the File”

Before running a command, identify its starting directory, target, and effect. This matters particularly when it creates or replaces a file.

Exercise scenario: you are inside ~/kubedojo-practice, and someone asks you to inspect recipes/appetizers/bruschetta.txt. The path does not start with /, so it is relative to your current working directory. The shell will start where you are standing, look for a directory named recipes, then a directory named appetizers, then a file named bruschetta.txt. If any one of those names is missing or misspelled, the command fails at that step.

Terminal window
pwd
/home/yourname/kubedojo-practice

Example relative path (run after creating the practice tree in the hands-on exercise, or when that file already exists):

cat recipes/appetizers/bruschetta.txt

From the workspace, the command reads the appetizer file. From your home directory, the same relative path instead starts at home and points to a different location. Use pwd to check the starting point.

Now compare that with the absolute version. An absolute path is longer, but the shell does not need your current working directory to interpret it. The command below points to one concrete location from the root of the filesystem tree, so it can work from your home directory, the project directory, or a log directory, provided the file exists and permissions allow access.

Example absolute path — adjust yourname to match your account:

cat /home/yourname/kubedojo-practice/recipes/appetizers/bruschetta.txt

Choose a relative path when its starting directory is known. An absolute path does not depend on the current directory, but still needs to exist and identify the intended file on the machine where it runs.

The same trace method works for mkdir -p. Still inside your newly created workspace, run pwd and confirm its path before continuing. When you run mkdir -p recipes/desserts, the shell starts there and ensures that each named directory exists in order. If recipes exists, it keeps going; if desserts is missing, it creates it. Adding kubedojo-practice/ here would incorrectly create a second project inside the first. Stop on any error before continuing to touch or >.

Terminal window
pwd
mkdir -p recipes/desserts

This is why mkdir -p is common in setup instructions. It avoids forcing learners to create every parent directory manually, and it makes repeated practice less fragile. If you run the same command again, it should still leave the directory structure in the desired state. That property, where a command can be repeated without causing unnecessary change, is valuable in automation even though this module is only introducing the beginner version of the idea.

touch deserves the same careful reading because it can be misunderstood. In the lab, touch recipes/desserts/tiramisu.txt creates a blank file when the file does not exist. If it already exists, the command does not erase the ingredients; it updates the file’s timestamp. That makes touch a poor command for adding content but a useful command for creating placeholders before another tool writes to them.

Terminal window
touch recipes/desserts/tiramisu.txt

With Bash’s default redirection settings, > creates the target or replaces its contents; a customized shell may instead refuse an overwrite. Here, echo 'Ingredients: coffee, mascarpone, ladyfingers, cocoa' > recipes/desserts/tiramisu.txt replaces only your disposable recipe. On a real configuration file, the same redirect can destroy settings, so check the destination before running it.

Terminal window
echo 'Ingredients: coffee, mascarpone, ladyfingers, cocoa' > recipes/desserts/tiramisu.txt

Pause and predict: if tiramisu.txt already contains three lines and you run the redirect command above, how many ingredient lines will remain afterward? Commit to a number before opening the reveal.

Check your prediction

Exactly one line remains, because > replaces the file’s entire content with the command’s output. The three previous lines are gone the moment the redirect runs, no matter how much work went into them. Later terminal modules will introduce append redirection and editors, but the safe habit begins here: know whether a command reads, creates, replaces, or only changes metadata before you press Enter.

This “read, create, replace, or move” classification also helps with command fear. pwd only reads your current location. ls reads directory metadata. cat, head, and tail read file contents. mkdir creates directories. touch may create a file or update a timestamp. cd changes your shell’s current location but does not move files on disk. Once you classify a command this way, you can decide how cautious you need to be.

CommandMain EffectRisk Level for Beginner Practice
pwdReads current working directoryVery low because it changes nothing
lsReads directory entriesVery low because it changes nothing
cdChanges shell locationLow because it does not edit files
catPrints file contentsLow, but be careful with secrets
headPrints the beginning of a fileLow, with the same secret caution
tailPrints the end of a fileLow, especially useful for logs
mkdir -pCreates missing directoriesModerate because it changes the tree
touchCreates an empty file or updates timestampModerate because it changes metadata
>Redirects output, replacing existing contents under Bash’s default settingsHigh because it can destroy existing content

The secret caution in the table is not theoretical. Kubernetes client configuration may include certificate data, tokens, context names, user names, and cluster addresses. A beginner who runs cat ~/.kube/config on a shared screen may reveal more than intended. You still need to know where the file lives, but reading the whole thing into the terminal is not always the right inspection method.

When paths include hidden directories, trace them exactly the same way. The path ~/.kube/config starts by expanding ~ to the user’s home directory, then enters the hidden .kube directory, then names the config file. The dot does not make .kube harder for the shell to find. It only hides the directory from a default listing, which is why direct commands can work even when plain ls did not show the name.

The following Kubernetes and SSH paths are illustrative, not prerequisites; do not inspect real configuration or keys for this exercise.

ls -a ~
ls -l ~/.kube

There is another subtle lesson here: a path can be correct while access still fails. If the path exists but permissions do not allow you to read the file or enter the directory, the shell reports a permission error instead of a missing-file error. That difference matters during diagnosis. “No such file or directory” points toward spelling, starting location, or missing parents. “Permission denied” points toward ownership, permission bits, or a directory on the path that cannot be traversed.

ls -ld ~/.ssh
ls -l ~/.ssh

The first command asks about the .ssh directory itself, while the second asks about what is inside it. If you cannot enter a directory, inspecting the directory entry with ls -ld is often more useful than trying to list the contents. This pattern carries into system directories as well, although you should be careful and avoid changing files under /etc or /var unless a lab or administrator explicitly tells you to.

On a kubeadm control-plane node, static Pod manifests live under /etc/kubernetes/manifests/. Kubernetes normally places container logs under /var/log/pods/. The exact logging setup matters, so recognize the path in the documentation rather than assuming every log is a plain file in the same directory.

Illustrative node-specific commands; these paths need not exist on your machine:

ls -l /etc/kubernetes/manifests/
tail -n 20 /var/log/syslog

Those commands may not work on every personal machine because not every machine is a Kubernetes node, and not every Linux distribution uses the same log filenames. That is fine. The lesson is not that you should memorize every possible production path today. The lesson is that when documentation gives you a path, you can decide whether it is absolute, relative, user-specific, hidden, a file, a directory, or a log-like target.

Before you move on, practice explaining one command out loud: tail -n 20 /var/log/syslog. A good translation is “starting from the root directory, go into var, then log, then read the newest twenty lines from syslog.” That translation contains the path type, the route, the file target, and the reason tail was chosen. If you can make that translation, you are no longer just copying terminal symbols.

There is one more layer to that translation: every path has checkpoints. For /var/log/syslog, the shell needs / to exist, then var, then log, then the final file. For recipes/appetizers/bruschetta.txt, it needs the current directory to be what you think it is, then recipes, then appetizers, then the final file. When a command fails, those checkpoints give you a debugging plan instead of leaving you with a vague sense that “the terminal is broken.”

The first checkpoint is your starting point, so pwd is the first repair command when a relative path fails. If the starting point is wrong, every relative path after it is also wrong. The second checkpoint is each parent directory, which you can inspect with ls one level at a time. The final checkpoint is the target itself, where you decide whether it should be a file, a directory, or a hidden name that requires ls -a to appear in listings.

The following checkpoint examples assume the appetizer files from the hands-on exercise already exist:

pwd
ls
ls recipes
ls recipes/appetizers

Those four commands are deliberately plain. They do not fix anything by themselves, but they turn confusion into evidence. If ls recipes fails, the problem is near the project root. If ls recipes/appetizers works but cat recipes/appetizers/bruschetta.txt fails, the parent directories are probably correct and the final filename or permissions deserve attention. Good terminal troubleshooting is often this kind of narrowing.

The same narrowing helps with permission problems. Suppose a path exists, but reading the final file fails with “Permission denied.” You can inspect the file with ls -l if you can reach it, and you can inspect parent directories with ls -ld if entering the path is the problem. A missing read bit on the file is different from a missing execute bit on a parent directory, even though both can stop you from getting useful content.

ls -ld recipes
ls -ld recipes/appetizers
ls -l recipes/appetizers/bruschetta.txt

You can also use checkpoints to avoid accidental writes. Before creating a file with touch or replacing content with >, run pwd and ls to confirm the destination. In a beginner lab, the worst mistake is usually a messy practice directory. In professional work, writing to the wrong path can overwrite a configuration file, create a directory structure in the wrong place, or leave a script writing logs where nobody expects to find them.

NeedFirst Command to TrySafer Follow-Up
Confirm your locationpwdCompare the path with the command you planned to run
Inspect a directorylsUse ls -la when hidden files may matter
Enter a known directorycd pathRun pwd afterward while learning
Read a tiny filecat fileUse head if you are unsure about size
Inspect recent log linestail -n 20 fileIncrease the line count only if needed
Diagnose accessls -l fileUse ls -ld directory for the directory itself
MistakeWhy It HappensHow to Fix It
Trying to cd into a regular fileThe path exists, so the beginner assumes it can be entered like a folderUse cat, head, or tail for files; use cd only for directories
Forgetting the space between command and pathThe command and argument visually blend together while typing quicklyWrite commands as verb plus target, such as cd Documents. In Bash, Tab attempts to complete the text before the cursor
Using backslashes \ in Linux or macOS pathsWindows examples use backslashes, so the habit carries overUse forward slashes, such as /home/you/Documents, in Unix-like shells
Creating a file when a program expects a directorytouch and mkdir both create names, but the resulting object type differsUse mkdir for containers and touch for empty files, then confirm with ls -l
Getting lost in nested directoriesRelative paths stop matching the learner’s mental modelRun pwd, list nearby files with ls, or return home with cd ~ before continuing
Missing a hidden configuration filePlain ls intentionally hides names that start with a dotRun ls -a or address the file directly, such as cat ~/.bashrc
Printing a huge log with catcat is remembered as the file-reading command, so it gets used for every file sizeUse tail -n 20 for recent log entries or head -n 20 for the beginning
Misreading directory execute permissionThe letter x sounds like “run,” which is confusing for directoriesRemember that x on a directory means you can enter or traverse it
Question 1: You are reading documentation that tells you to inspect `~/.kube/config`, but your terminal is currently in `/var/log/pods/`. Where does `~` point, and why is it useful here?

~ points to the current user’s home directory, such as /home/yourname on many Linux systems or /Users/yourname on macOS. The current working directory does not change that expansion, so the shell does not look under /var/log/pods/. This shortcut is useful because documentation can refer to a user’s personal Kubernetes configuration without knowing the user’s exact account name. It also keeps the command portable across machines where home directories have different prefixes.

Question 2: A deployment script works only when launched from the project root because it uses `cd config/`. What path problem is the script relying on, and what would make it safer?

The script relies on a relative path, so config/ is resolved from whatever directory the caller happens to be in. When the script starts somewhere else, the shell looks for a different config directory and the command fails. A safer script would use an absolute path or derive the path from the script’s own location before changing directories. The key diagnosis is that relative paths are context-dependent, while absolute paths start from /.

Question 3: You downloaded a project that includes `.env`, but plain `ls` does not show it. What should you run, and what security assumption should you avoid?

Run ls -a to include names that start with a dot. The leading dot hides the name from default listings; it does not protect the contents. If .env contains credentials, permissions and careful handling matter more than the leading dot.

Question 4: You are in `/home/user/projects/app/src` and need to read `/home/user/projects/app/README.md`. What relative command would work, and why might it be preferable interactively?

cat ../README.md would work because .. moves from src to its parent directory, app, and then names the README.md file. In an interactive session, the relative path is shorter and easier to type than the full absolute path. It is also clear because you already know your current location inside the project. In a script, you would be more cautious because the starting directory may not be stable.

Question 5: A sensitive file has permissions `-rw-r-----`, is owned by `admin`, and belongs to group `support`. What do the ordinary mode bits grant a non-owner user in `support`?

The group bits grant read but not write. The owner bits grant admin read and write; they do not automatically apply to other group members. Actual access also depends on search permission on parent directories and any additional access rules or privileges.

Question 6: A node log has grown very large, and you need the newest errors from the bottom. Which command shape should you choose, and why is `cat` a poor first choice?

Use a command such as tail -n 20 /var/log/syslog so the terminal prints only the newest lines. cat /var/log/syslog is a poor first choice because it prints the whole file, which can flood the terminal and bury the recent error you were looking for. tail matches the structure of append-style logs, where new entries are written at the end. You can increase the number after -n if the first view is too small.

Question 7: You run `ls -l recipes` and see the files inside the directory, but you wanted the permissions on the `recipes` directory itself. What command should you use, and what does it change?

Use ls -ld recipes. The -l option asks for long format, while -d tells ls to show the directory entry itself instead of listing its contents. This matters when diagnosing whether you can enter, list, or write inside the directory. Without -d, you may accidentally inspect the children and miss the permission problem on the parent.

Hands-On Exercise: Building Your First Directory Structure

Section titled “Hands-On Exercise: Building Your First Directory Structure”

In this exercise, you will create a small recipe project, navigate through it, compare file-reading commands, inspect permissions, and reveal a controlled dotfile. Predict each command’s output before running it, then compare the terminal response with your prediction. The same path and reading decisions apply when you later inspect a manifest or log.

Continue in the disposable workspace and complete the file-creating examples above first, including the desserts example. If you are repeating the lesson, create a fresh workspace with an unused name; do not adopt an existing project. Run each command separately and stop on any error, especially a failed mkdir or cd, before creating or overwriting files.

Terminal window
pwd
ls -a

Confirm that pwd identifies your owned workspace and its top level contains recipes, shopping-list.txt, and .practice-hidden. Unexpected entries mean stop and establish a fresh workspace. The tasks reuse only the disposable recipe files you create in this lesson.

  1. Create the project directories. Use mkdir -p so the command creates every parent directory needed for the nested structure.
Terminal window
mkdir -p recipes/appetizers
mkdir -p recipes/main-courses
Solution notes for task 1

The -p option allows each command to create parent directories that do not exist yet. After these commands, your workspace should contain a recipes directory, and recipes should contain three category directories. If a command prints no output, that usually means it succeeded.

  1. Confirm your location in the project and list its top level. You are already inside the workspace; do not enter a second nested project.
Terminal window
pwd
ls

Expected minimum entry (the earlier examples also leave shopping-list.txt):

recipes
Solution notes for task 2

The pwd output should identify your workspace, and ls should include recipes. The earlier examples also created shopping-list.txt, so that extra entry is expected when following the whole page. If the location or entries are unfamiliar, stop before writing files and return to the workspace setup instructions.

  1. Create the remaining recipe files. The worked example already created tiramisu.txt.
Terminal window
touch recipes/appetizers/bruschetta.txt
touch recipes/main-courses/pasta-carbonara.txt
Solution notes for task 3

Each path is relative to your chosen workspace, which is why it starts with recipes/ instead of /home/.... If one command fails with “No such file or directory,” inspect the directory names with ls recipes and check for a spelling mismatch.

  1. Write simple content into the files. The > character redirects the output of echo into the target file.
Terminal window
echo 'Ingredients: bread, tomatoes, basil, olive oil' > recipes/appetizers/bruschetta.txt
echo 'Ingredients: pasta, eggs, pancetta, parmesan' > recipes/main-courses/pasta-carbonara.txt
Solution notes for task 4

The > redirect replaces the file’s contents with the text produced by echo. Here you are intentionally writing only your disposable lesson files. In real work, be careful with > because it overwrites existing content; later modules will cover safer editing habits.

  1. Compare how much each tool displays. First read the individual files:
Terminal window
cat recipes/appetizers/bruschetta.txt
head recipes/main-courses/pasta-carbonara.txt
tail recipes/desserts/tiramisu.txt

All three files have one line, so the outputs alone do not show the difference. From your owned workspace, run ls -a and confirm recipe-summary.txt is absent before creating it. Stop if that name already exists. Predict which ingredient lines the final three commands will display:

Terminal window
cat recipes/appetizers/bruschetta.txt recipes/main-courses/pasta-carbonara.txt recipes/desserts/tiramisu.txt > recipe-summary.txt
cat recipe-summary.txt
head -n 1 recipe-summary.txt
tail -n 1 recipe-summary.txt
Solution notes for task 5

The first cat combines the files in the given order. The second displays all three lines; head displays the bread line and tail the coffee line. Choose the command by how much of the file you need to inspect.

  1. Inspect permissions on a file and a directory. Predict the first character before you run each command.
Terminal window
ls -l recipes/appetizers/
ls -ld recipes
Solution notes for task 6

The file entry for bruschetta.txt should begin with - because it is a regular file. The entry for recipes should begin with d because it is a directory. The exact read, write, and execute bits may vary by system defaults, but you should be able to split them into owner, group, and others.

  1. Move around and recover your location. Use pwd after each movement until the mental model feels automatic.
Terminal window
cd recipes/desserts
pwd
cd ..
pwd
cd -
pwd
cd ~
pwd
Solution notes for task 7

The first pwd should identify recipes/desserts inside your chosen workspace. After cd .., it should identify that workspace’s recipes directory. cd - returns to recipes/desserts; after cd ~, pwd identifies your home directory. If any prediction is wrong, pause and explain which relative path assumption changed.

Diagnostic Challenge: Three Failures, No Recipe

Section titled “Diagnostic Challenge: Three Failures, No Recipe”

The tasks above told you which command to run at each step. This challenge gives you only symptoms. Diagnose all three using nothing but the checkpoint commands from this module — pwd, ls, ls -a, ls -l, ls -ld, and id — and write down your diagnosis for each symptom before opening the reveal. Do not fix anything yet; the goal is to name the exact checkpoint where each failure happens.

Symptom 1: wrong starting point. You are inside ~/kubedojo-practice/recipes/desserts and run cat recipes/appetizers/bruschetta.txt. The shell answers No such file or directory, but you are sure the file exists because you created it in task 3. Where did the relative path actually start, and which directory did the shell go looking in?

Symptom 2: file treated as a directory. From inside the project, you run cd recipes/desserts/tiramisu.txt and the shell refuses with Not a directory. What kind of entry does the path end in, and which character of an ls -l permission string would have told you that in advance?

Symptom 3: access, not spelling. A shared recipe file exists, but reading it returns Permission denied. Suppose ls -l shows -rw-r-----, your teammate owns it, and its group is absent from your id output. What do you inspect, and who can arrange access?

Hint: choose a checkpoint

Start with the current directory for symptom 1, the entry type for symptom 2, and the file and parent permissions for symptom 3.

One possible diagnosis for each symptom

Symptom 1 is a relative-path failure. Running pwd shows you are in .../recipes/desserts, so the shell looked for .../recipes/desserts/recipes/appetizers/bruschetta.txt. Walking the checkpoints confirms it: ls shows no recipes entry here, so the failure happens at the very first checkpoint — the starting point was wrong, not the filename.

Symptom 2 is a type mismatch. tiramisu.txt is a regular file, and cd can only enter directories. Running ls -l recipes/desserts/ shows the entry’s permission string beginning with - instead of d, which is the advance clue that the target can be read with cat but never entered.

Symptom 3 is a permission failure. Inspect the file with ls -l and its parent directories with ls -ld. Under ordinary mode-bit checks, the others segment --- prevents your read; additional access rules need separate inspection. Ask the owner or an authorized administrator to arrange access.

If you diagnosed all three without opening the reveal, you have the troubleshooting loop this module was building toward: confirm the starting point with pwd, walk the path one checkpoint at a time with ls, and separate “the path is wrong” from “the path is fine but access is denied” with ls -l and ls -ld.

You’ve completed this exercise when you can:

  • Navigate to your home directory with cd ~.
  • Create nested directories with mkdir -p.
  • Create files with touch.
  • Write content to files with echo "text" > file.
  • Explain why cat, head -n 1, and tail -n 1 show different amounts of the summary file.
  • Check file permissions with ls -l.
  • Check directory permissions with ls -ld.
  • View hidden files with ls -a.
  • Navigate with cd, cd .., and cd ~.
  • Diagnose a wrong-path, file-vs-directory, or permission failure using pwd, ls, ls -l, and ls -ld.

You may keep your recipe files. To remove them, follow the owned-workspace cleanup in Module 0.3, using only the disposable workspace you created here. Inspect it first and stop if its contents or ownership are unfamiliar.

Next Module: Module 0.5: Editing Files — Learn how to put real content inside files using a terminal text editor.