Almost every server you will meet in DevOps runs Linux. Cloud virtual machines, containers, build servers and most websites sit on it. That is why this course starts with Linux before any cloud or container tool: if you are comfortable in a Linux terminal, everything later is easier. You do not have to love it. You only need to be able to move around, read files, change things carefully and understand error messages.
Why do we need it?
Servers, containers, build machines and most cloud services run Linux. If you can move around a Linux terminal and read its messages, you can fix problems on all of them. Without it, every other DevOps tool feels like magic that you cannot debug.
A real-life example
Think of the terminal as a text message chat with your computer. You type a short request, and it answers. A graphical desktop is like pointing at things, which is fine for you but not possible over a network connection to a server in another country. Typing is how you give clear, repeatable instructions that a script can also follow.
What Linux is
Linux is an operating system kernel. The kernel is the core part that talks to the hardware: it decides which program gets the processor, manages memory, reads disks and handles the network. Around the kernel sit tools, libraries and programs. A bundle of the kernel plus those tools is called a distribution, or distro. Linux is free and open source, which means anyone can read, change and share the code, and that is a big reason it spread so widely.
The layers, simply
- Hardware: the processor, memory, disks and network card.
- Kernel: controls the hardware and gives programs a safe way to use it.
- Shell: a program that reads the commands you type, for example Bash.
- Programs and services: everything else, from a text editor to a web server.
Which distribution
- Ubuntu and Debian: very common on servers and in tutorials. They use the
aptpackage tool. Ubuntu Server is a good first choice. - RHEL, Rocky Linux, AlmaLinux and CentOS Stream: the Red Hat family, common in large companies. They use
dnf(older ones useyum). - Amazon Linux: the default on many AWS machines, in the Red Hat style.
The commands in this course work on all of them unless the lesson says otherwise. The biggest difference you will notice is the package tool and the exact location of a few files.
Ways to try Linux safely
- WSL on Windows: Windows Subsystem for Linux gives you an Ubuntu terminal inside Windows. It is the quickest start for many learners.
- A virtual machine: install VirtualBox or similar and run Ubuntu in a window. Mistakes cost nothing, because you can delete the machine.
- A cloud server: a small virtual machine from a provider. It is real, but remember to switch it off, and set a billing alert.
- macOS: the terminal is similar to Linux for many commands, though a few tools differ.
The terminal and the shell
The terminal is the window. The shell is the program inside it that understands your commands. You type a command, press Enter, and the shell runs it and prints the result. A command has a name, then options that start with a dash, then arguments such as file names. For example, in ls -l /var/log, ls is the command, -l is an option and /var/log is the argument.
Commands you will use every day
pwdshows where you are.cd foldermoves into a folder,cd ..goes up one level, andcd ~goes to your home folder.lslists files.ls -lashows details and hidden files (names that start with a dot).mkdir namemakes a folder andmkdir -p a/b/cmakes a whole path.cp from tocopies andmv from tomoves or renames.cp -rcopies a folder.rm filedeletes a file.rm -r folderdeletes a folder and everything in it. There is no undo.cat fileprints a file.less filelets you scroll through it, andqquits.head -n 5 fileandtail -n 5 fileshow the first and last lines.tail -f filekeeps following new lines, which is perfect for logs.grep word filefinds lines that contain a word.grep -r word foldersearches a whole folder.find /path -name "*.log"finds files by name.man commandopens the manual for a command, andcommand --helpgives a short summary.
Paths and the folder map
Linux has one big tree that starts at /, called root. A path that starts with / is absolute, and works from anywhere. A path that does not is relative to where you are. A few folders matter for DevOps: /etc holds configuration, /var/log holds logs, /home holds users’ files, /tmp is for temporary files, /usr/bin holds programs and /opt is often used for extra software. When something breaks, the answer is very often in a file under /etc or /var/log.
Work with files, step by step
mkdir -p ~/practice/logs
cd ~/practice
echo "hello devops" > notes.txt
cat notes.txt
cp notes.txt logs/notes-copy.txt
ls -l logs
mv logs/notes-copy.txt logs/old-notes.txt
grep devops logs/old-notes.txt
The > sign sends the output of a command into a file instead of the screen, and replaces what was there. >> adds to the end instead. The pipe | sends the output of one command into another, and you will use it constantly, for example ls -l | grep log.
Two habits that save you
- Use Tab. Press Tab to complete file names and commands. It saves typing and catches spelling mistakes.
- Read before you run. If you paste a command from the internet, read what it does first, especially if it contains
sudo,rmor a pipe intosh.
Architecture diagram
Here is the idea as a simple picture. You can use the same diagram in your own notes.
flowchart TD
You[You type a command] --> Shell[Shell: Bash]
Shell --> Prog[Program, for example ls]
Prog --> Kernel[Linux kernel]
Kernel --> HW[(Disk, memory, network)]
HW --> Kernel --> Prog --> Shell --> Out[Output on screen]
How to check it worked
pwdshows the folder you expect after eachcd.- You can create, copy, move, read and delete a file without looking up the commands.
- You can say what
/etcand/var/logare for.
How companies use it
Almost every company that runs web services has Linux servers. DevOps engineers log in with SSH, read logs, edit configuration, install packages and run scripts. Containers are Linux processes, so Docker and Kubernetes skills depend on Linux knowledge. Ubuntu is common for learning and in startups, and Red Hat style systems such as Rocky Linux or Amazon Linux are common in larger companies.
Common errors and how to fix them
- command not found. The program is not installed or not on your PATH. Check the spelling, then install it with apt or dnf.
- Permission denied. You lack the right on that file or folder. Check with
ls -landid, and usesudoonly if the task needs it. - No such file or directory. The path is wrong. Use
pwdandls, and press Tab to complete names. - Deleted the wrong files with rm. There is no undo. Use
lsfirst with the same pattern, avoidrm -rfwith wildcards and keep backups.
Best practices
- Practise on a throwaway machine, not a production server.
- Use Tab completion and the up arrow for history.
- Read the manual with
manand--helpbefore you guess. - Prefer relative short commands you understand to pasted one-liners you do not.
- Keep notes of commands that worked.
Interview questions with simple answers
- What is Linux? An open source operating system kernel, usually used inside a distribution that adds tools and a package manager.
- What is a distribution? A bundle of the kernel, tools and package manager, such as Ubuntu or Rocky Linux.
- What is the difference between a shell and a terminal? The terminal is the window. The shell is the program that reads and runs your commands.
- Which command shows your current folder?
pwd. - What does `ls -la` show? All files, including hidden ones, with details.
- What is `/etc` used for? Configuration files.
- Where are logs usually kept? In
/var/log, and in the journal on systemd systems. - What does the pipe `|` do? Sends the output of one command into another.
- How do you copy a folder?
cp -r source destination. - How do you find a file by name?
find /path -name "name".
Practical exercises
Try each one yourself before you look at the hint. Struggling for a few minutes is how the skill sticks.
- Make the folders
lab/logsin one command and create three empty files inlab. Hint:mkdir -pandtouch. - Write a line into a file, then add a second line without erasing the first. Hint: One arrow replaces, two arrows add.
- Find all
.conffiles under/etc. Hint:findwith-name. - Show the last 3 lines of a long file and follow it as it grows. Hint:
tail -nandtail -f. - Count how many files are in a folder using a pipe. Hint:
lsandwc -l.
Mini project: Practice server notebook
Create a folder called notebook. Inside, make commands.txt and add ten commands you learned, each with a one-line note. Make a logs folder, copy the file into it, rename the copy and search it with grep. Finish by listing the structure with ls -R.
Knowledge test
Answer the ten questions in the quiz at the end of this lesson. You pass with 60 percent. If an answer is wrong, read the explanation, then reread the part of the lesson it points to.