Skip to content

Beginner · Linux for DevOps · topic 5 of 53 · 30 min

The Linux filesystem and everyday commands

Explanation

Linux runs most servers, almost all containers and most CI runners, so DevOps work happens in a Linux terminal. Everything lives in one tree that starts at / (root), with standard places like /etc for settings and /var/log for logs. A small set of commands (pwd, ls, cd, mkdir, cp, mv, rm, cat, less, tail, find) and a package manager (apt or dnf) cover most daily work.

Why Linux matters in DevOps

Linux is a free, open-source operating system. Most cloud servers run it, nearly every container image is built on it, and the machines that run CI pipelines (called runners or agents) are usually Linux too. Kubernetes nodes run Linux. If you work in DevOps, you will spend a lot of time typing commands on Linux machines you never see physically.

Distributions

A distribution (distro) is Linux packaged with tools, a package manager and a release schedule. You will meet these most often:

DistributionWhere you see itPackage manager
Ubuntu (LTS releases)Cloud servers, CI runners, laptopsapt
DebianServers, base of many container imagesapt
RHEL, Rocky Linux, AlmaLinuxBanks, enterprises, telecomdnf
AlpineVery small container images (a few megabytes)apk

Rocky Linux and AlmaLinux are free rebuilds of Red Hat Enterprise Linux (RHEL). Ubuntu LTS (long-term support) versions come out every two years and get years of security updates, which is why servers use them.

The shell and the terminal

The terminal is the window where you type. The shell is the program inside it that reads your command, runs it and prints the result. The most common shell is bash; zsh is popular on laptops. The prompt, such as deploy@web1:~$, tells you the user (deploy), the machine (web1) and the current folder (~ means your home folder).

One tree, starting at /

Windows has drives like C: and D:. Linux has a single tree that starts at / (called root). Disks and other devices are attached, or mounted, somewhere inside that tree.

PathWhat lives there
/The top of the tree
/etcSystem and app configuration files, such as /etc/ssh/sshd_config and /etc/nginx/
/var/logLog files
/var/libApp data, for example /var/lib/docker and /var/lib/postgresql
/homeHome folders of normal users, such as /home/asha (root’s home is /root)
/usr/binPrograms (commands) installed by the system
/optOptional, third-party software, often your own apps
/tmpTemporary files, often cleared on reboot
/procNot real files: live information from the kernel, such as /proc/cpuinfo and /proc/meminfo

Absolute and relative paths

An absolute path starts with / and works from anywhere: /var/log/nginx/access.log. A relative path starts from the current folder: if you are in /var/log, then nginx/access.log points to the same file. Two special names help: . means "this folder" and .. means "the parent folder". So from /var/log/nginx, the path ../syslog means /var/log/syslog.

Everyday commands

bash
pwd                          # print the current folder
ls -la                       # list all files, including hidden ones, with details
cd /var/log                  # go to a folder (cd alone goes home, cd - goes back)
mkdir -p /opt/shop/releases  # make a folder and any missing parents
cp app.conf app.conf.bak     # copy a file
cp -r config/ backup/        # copy a folder and everything inside it
mv old.log archive.log       # move or rename
rm notes.txt                 # delete a file
rm -r old-build/             # delete a folder and its contents
touch deploy.log             # create an empty file (or update its time)
The commands you will type every day. Text after # is a comment.
Careful: rm has no recycle bin. rm -rf deletes folders without asking, and with sudo it can destroy a server. Common mistakes: running rm -rf with a variable that turned out empty (rm -rf "$DIR"/ becomes rm -rf /), or with a path typed in a hurry. Run ls on the exact path first, and never run rm -rf as root on a path you have not read twice.

Reading files

bash
cat /etc/os-release          # print a short file (which distro is this?)
less /var/log/syslog         # scroll a long file: q quits, /word searches
head -n 20 app.log           # first 20 lines
tail -n 50 app.log           # last 50 lines
tail -f app.log              # follow: keep printing new lines as they arrive
find /var/log -name "*.log" -mtime +7    # .log files older than 7 days
find / -type f -size +500M 2>/dev/null   # files bigger than 500 MB
tail -f is the command you will use most when watching a deployment.

Editing files on a server

Servers have no graphical editor, so learn one terminal editor. nano is simple: type, then Ctrl+O to save and Ctrl+X to exit. vim is on almost every machine: press i to insert text, Esc to stop inserting, then type :wq and Enter to save and quit, or :q! to quit without saving.

Installing software

bash
sudo apt update                # Ubuntu/Debian: refresh the package list
sudo apt install -y nginx      # install nginx without asking yes/no
sudo dnf install -y nginx      # RHEL/Rocky/Alma
apk add --no-cache curl        # Alpine, often inside a Dockerfile
Always refresh the package list with apt update before installing on Ubuntu.
Tip: Press Tab to complete file and command names, and the Up arrow to repeat earlier commands. Ctrl+R searches your command history. These save more time than any other trick.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

The Linux filesystem and everyday commands · 1/8

Linux for DevOps

Linux runs most servers, containers and pipeline runners, so this is where DevOps work happens.

Prefer a video by a teacher? Find free videos on “linux command line basics filesystem hierarchy for devops beginners” on YouTube ↗

In real life: Checking a release on a shop server

A DevOps engineer at an online grocery company in Hyderabad logs in after a release. cat /etc/os-release shows Ubuntu. ls -la /opt/shop/releases shows the new release folder. tail -f /var/log/nginx/error.log shows no new errors while she refreshes the site. find /var/log -name "*.gz" -mtime +30 lists old compressed logs filling the disk, which she reports for a cleanup job instead of deleting by hand.

bash
cat /etc/os-release | head -n 2
ls -la /opt/shop/releases
tail -f /var/log/nginx/error.log
Three commands to check a release.

Practice (0/3 done)

Task 1 · Question

You are in /var/log/nginx. Which absolute path does ../syslog point to?

Task 2 · Code · Python

Write normalise(cwd, path) that works out the absolute path a shell would use, without touching the disk. cwd is the current folder (always absolute). If path starts with "/", start from the root; otherwise start from cwd. Ignore empty parts and ".", and let ".." remove the last folder (but never go above "/"). Return the result as a string starting with "/", with no trailing slash (except the root itself, "/").

Task 3 · Question

Where would you normally look for the configuration of the SSH server?

Quick quiz

Question 1

1.Which folder holds log files on a typical Linux server?

Question 2

2.What does mkdir -p /opt/app/releases/v2 do if /opt/app does not exist yet?

Question 3

3.Which command keeps showing new lines of a log file as they are written?

Question 4

4.Which package manager do you use on Rocky Linux?

Question 5

5.In vim, how do you save the file and quit?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which folder holds log files on a typical Linux server?

Answer: /var/log

/var/log holds system and many application logs.

What does mkdir -p /opt/app/releases/v2 do if /opt/app does not exist yet?

Answer: Creates all missing folders in the path

The -p flag creates every missing parent folder and does not complain if they exist.

Which command keeps showing new lines of a log file as they are written?

Answer: tail -f app.log

tail -f follows the file and prints new lines as they arrive.

Which package manager do you use on Rocky Linux?

Answer: dnf

Rocky Linux and other RHEL-family systems use dnf. apt is for Debian and Ubuntu, apk for Alpine.

In vim, how do you save the file and quit?

Answer: Esc, then :wq and Enter

:wq writes and quits. :q! quits without saving. Ctrl+X exits nano, not vim.

You are in /etc. Which absolute path does the relative path ../home/asha mean?Related

Answer: /home/asha

.. takes you from /etc up to /, then into home/asha.

From The filesystem hierarchy and paths

Which command copies the folder /etc/ssh with all owners and permissions kept?Related

Answer: cp -a /etc/ssh /backup

-a (archive) copies recursively and keeps owner, permissions and times.

From Working with files: ls, cp, mv, rm, links and find

Which command shows the RHEL release?Related

Answer: cat /etc/redhat-release

/etc/redhat-release holds the release line. uname -r shows the kernel version instead.

From What Linux and Red Hat Enterprise Linux are

vim says "E45: readonly option is set" on /etc/hosts. Most likely cause?Related

Answer: You opened a root-owned file as a normal user without sudo

Open it again with sudo vim /etc/hosts.

From Editing files with vim

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Linux for DevOps” before its exam: Users, groups and permissions, Processes, signals and systemd services, Bash scripting, text tools and cron, Linux networking for DevOps.
  2. Module 2 exam: Linux for DevOps · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Git in depth. 53 topics left in the course before the final exam.

← Previous: The DevOps toolchain and your learning roadmap