Lesson 2 of 12 · 9 min · Working with files

The filesystem: layout, paths and everyday file commands

Covers: Ubuntu 24.04 LTS, bash 5.2, GNU coreutils 9.4. Updated 13 Nov 2026. Part of the DevOps Engineer roadmap.

What you will learn

  • The single directory tree, and what lives in /etc, /var, /home, /usr, /tmp, /proc and others
  • Absolute and relative paths, ., .. and ~
  • cd, ls, mkdir, cp, mv, rm, touch, cat and less
  • How to delete without regret

In simple words

Think of a Linux system as one big cupboard with labelled shelves. Everything, whether a document, a program or a setting, sits on some shelf, and its address tells you exactly where. This lesson shows you the main shelves and the handful of commands for moving around and for creating, copying and deleting files.

Words to know

  • Directory: a folder. It holds files and other folders.
  • Path: the address of a file, such as /home/asha/notes.txt.
  • Absolute path: the full address, starting from the top (/). It works from anywhere.
  • Relative path: an address that starts from the folder you are in now.

One tree, not drive letters

Windows has C: and D:. Linux has one tree that starts at / (called "root", not to be confused with the root user). Extra disks are mounted at a directory inside the tree, for example a data disk at /data. Programs do not care which disk a path is on.

The layout follows a convention (the Filesystem Hierarchy Standard). These are the directories you will use every week:

Path What lives there
/etc System configuration files, as text. Where you edit nginx, ssh, cron settings
/var Data that changes while the system runs: logs in /var/log, caches, spool, databases in /var/lib
/home One directory per user (/home/asha). /root is the root user's own home
/usr Installed programs and libraries. On modern distributions /bin, /sbin and /lib are links to /usr/bin, /usr/sbin, /usr/lib
/opt Optional third-party software, installed as one folder each
/tmp Temporary files that any user can create. Often cleared on reboot
/proc, /sys Not real files: the kernel's live view of processes and devices. You read them like files
/dev Device files such as disks (/dev/sda) and special ones like /dev/null (a bin that swallows everything)
/run Runtime state since boot: process ids, sockets
/boot The kernel and boot loader files

"Everything is a file" is the core idea: a text document, a disk, a terminal and a running process's details are all reached by path with the same tools (cat, ls, redirection). For example cat /proc/cpuinfo shows your CPU, and cat /etc/os-release names the distribution.

Paths

A path says where something is. There are two kinds:

  • Absolute: starts with / and works from anywhere: /var/log/syslog.
  • Relative: does not start with / and is read from your current directory: logs/app.log.

Special names: . is the current directory, .. is its parent, ~ is your home directory.

mkdir -p /tmp/demo/projects/app    # -p creates missing parents, and is not an error if it exists
cd /tmp/demo
pwd
touch projects/app/main.py projects/notes.txt
/tmp/demo

tree (install it with apt-get install -y tree) draws the structure:

.
`-- projects
    |-- app
    |   `-- main.py
    `-- notes.txt

3 directories, 2 files

cd with no argument goes home, and cd - returns to the previous directory.

Listing

ls            # names only
ls -l         # long: permissions, owner, group, size, date, name
ls -la        # include hidden (dot) files
ls -lh        # sizes in human units: 4.0K, 12M
ls -lt        # newest first
ls -ld /tmp   # about the directory itself, not its contents

Create, copy, move, delete

cp notes.txt notes.bak              # copy a file
cp -r projects projects-backup      # -r copies a directory and everything in it
mv notes.bak old-notes.txt          # move or rename (same command)
mv old-notes.txt projects/          # move into a directory
rm projects/old-notes.txt           # delete a file
rmdir emptydir                      # delete an empty directory
rm -r projects-backup               # delete a directory and its contents

Notes that matter:

  • mv is a rename when source and destination are in the same place, and a move otherwise. Either way it overwrites an existing destination file silently. Add -i to be asked first.
  • There is no recycle bin. rm removes the name straight away. Before running rm -r on a path you typed, run ls on the same path first.
  • rm -rf /some/dir forces deletion without questions. The classic disaster is an unset variable making rm -rf "$DIR/" become rm -rf /. Quote variables, and prefer rm -r without -f, so a typo asks questions.

Looking inside files

cat a.txt              # print the whole file
less /var/log/syslog   # page through a long file: space = next page, / = search, q = quit
head -n 5 a.txt        # first 5 lines
tail -n 5 a.txt        # last 5 lines
tail -f app.log        # keep following new lines as they are written (Ctrl+C to stop)
wc -l a.txt            # count lines

tail -f is the most used command during incidents, because it shows a log as it happens.

Wildcards (globbing)

The shell expands patterns before the command runs:

  • * matches any characters: ls *.log
  • ? matches one character: ls file?.txt
  • [abc] matches one of a set: ls report-[123].csv
  • {a,b} expands to alternatives: mkdir -p site/{css,js,img}

Because the shell does the expanding, rm *.log runs rm with a list of actual file names. If nothing matches, bash passes the pattern itself unchanged, which is why you sometimes see errors quoting *.log.

Common mistakes

  • Spaces in names. rm my file tries to delete two things, my and file. Quote: rm "my file".
  • Relative paths from the wrong place. Run pwd when a command says "No such file or directory" for something you are sure exists.
  • Editing in /tmp and expecting it to stay. /tmp is for temporary data.
  • Treating /proc files as storage. They are generated by the kernel when read.

Try it yourself

  1. Create ~/lab/{logs,config,scripts} in one command. Put an empty app.log in logs. Show the structure with ls -R ~/lab.
  2. Copy ~/lab/logs to ~/lab/logs-old and then delete the copy, checking with ls before and after.
  3. Use ln -s to create ~/lab/current pointing to ~/lab/config, then ls -l ~/lab to see the arrow.
  4. Open /etc/os-release with less, search for VERSION with /, and quit.

Check yourself

What is the difference between /home/asha/app and app?

The first is an absolute path and works from anywhere. The second is relative to the current directory, so it only works where app actually is. ~/app for user asha means the same as the first.

What does mkdir -p a/b/c do that mkdir a/b/c does not?

It creates any missing parent directories (a and a/b) and does not complain if directories already exist. Without -p the command fails when a/b is missing.

Why is rm -rf $DIR/* dangerous in a script, and how do you make it safer?

If DIR is empty or unset it expands to rm -rf /*. Quote and guard it: rm -rf "${DIR:?DIR is not set}"/*, which aborts when DIR is empty, or avoid -f and test the variable first.

Which directory would you look in for an application's logs, and which for its configuration?

Logs under /var/log (or the application's directory under it), configuration under /etc.

Interview questions

What is the difference between a hard link and a symbolic link?

A hard link is another name for the same inode (the same data) and cannot cross filesystems or point to directories. A symlink is a separate file holding a path; it can cross filesystems and point to directories, and it breaks if the target is removed.

What are /proc and /dev?

/proc is a virtual filesystem where the kernel exposes process and system information as files. /dev holds device files that give access to hardware and pseudo-devices such as /dev/null and /dev/zero.

How do you see what is filling up a directory? (Preview of the troubleshooting lessons)

du -sh * inside the directory shows the size of each entry; sort with du -sh * | sort -h.

Summary

  • Linux has one tree starting at /; know /etc (config), /var/log (logs), /home, /usr, /tmp and the virtual /proc and /dev.
  • Absolute paths start with /; relative ones start where you are. ., .. and ~ are shortcuts.
  • cp -r, mv, rm -r, mkdir -p, ln -s, less and tail -f cover most daily work.
  • Nothing is recoverable after rm. List first, quote variables, avoid -f unless needed.

Going deeper

See how much of this you can explain

A free mock interview asks you new questions on Linux for DevOps for DevOps Engineer and scores every answer, with what to fix.