Linux Basics: Distributions, the Terminal and Core Commands

DevOps and Cloud Engineering: Complete Course from Beginner to Advanced · Linux Fundamentals · 9 min read · Updated

Layers of Linux

  1. You type a command in the terminal.
  2. The shell reads it and starts the right program.
  3. The program asks the kernel for what it needs, such as reading a folder.
  4. The kernel talks to the disk and returns the answer, which the shell prints.

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 apt package 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 use yum).
  • 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

  1. WSL on Windows: Windows Subsystem for Linux gives you an Ubuntu terminal inside Windows. It is the quickest start for many learners.
  2. A virtual machine: install VirtualBox or similar and run Ubuntu in a window. Mistakes cost nothing, because you can delete the machine.
  3. A cloud server: a small virtual machine from a provider. It is real, but remember to switch it off, and set a billing alert.
  4. 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

  • pwd shows where you are. cd folder moves into a folder, cd .. goes up one level, and cd ~ goes to your home folder.
  • ls lists files. ls -la shows details and hidden files (names that start with a dot).
  • mkdir name makes a folder and mkdir -p a/b/c makes a whole path.
  • cp from to copies and mv from to moves or renames. cp -r copies a folder.
  • rm file deletes a file. rm -r folder deletes a folder and everything in it. There is no undo.
  • cat file prints a file. less file lets you scroll through it, and q quits.
  • head -n 5 file and tail -n 5 file show the first and last lines. tail -f file keeps following new lines, which is perfect for logs.
  • grep word file finds lines that contain a word. grep -r word folder searches a whole folder.
  • find /path -name "*.log" finds files by name.
  • man command opens the manual for a command, and command --help gives 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, rm or a pipe into sh.

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

  • pwd shows the folder you expect after each cd.
  • You can create, copy, move, read and delete a file without looking up the commands.
  • You can say what /etc and /var/log are 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 -l and id, and use sudo only if the task needs it.
  • No such file or directory. The path is wrong. Use pwd and ls, and press Tab to complete names.
  • Deleted the wrong files with rm. There is no undo. Use ls first with the same pattern, avoid rm -rf with 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 man and --help before 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

  1. What is Linux? An open source operating system kernel, usually used inside a distribution that adds tools and a package manager.
  2. What is a distribution? A bundle of the kernel, tools and package manager, such as Ubuntu or Rocky Linux.
  3. 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.
  4. Which command shows your current folder? pwd.
  5. What does `ls -la` show? All files, including hidden ones, with details.
  6. What is `/etc` used for? Configuration files.
  7. Where are logs usually kept? In /var/log, and in the journal on systemd systems.
  8. What does the pipe `|` do? Sends the output of one command into another.
  9. How do you copy a folder? cp -r source destination.
  10. 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.

  1. Make the folders lab/logs in one command and create three empty files in lab. Hint: mkdir -p and touch.
  2. Write a line into a file, then add a second line without erasing the first. Hint: One arrow replaces, two arrows add.
  3. Find all .conf files under /etc. Hint: find with -name.
  4. Show the last 3 lines of a long file and follow it as it grows. Hint: tail -n and tail -f.
  5. Count how many files are in a folder using a pipe. Hint: ls and wc -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.

Frequently asked questions

Do I need to install Linux as my main system to learn DevOps?

No. WSL on Windows, a virtual machine or a small cloud server is enough. Many people learn this way and keep their normal system.

What is the difference between a distribution and Linux?

Linux is the kernel. A distribution such as Ubuntu bundles the kernel with tools, a package manager and defaults, so you can install and use it.

Is there an undo for rm?

No. The shell does not use a recycle bin. Take care with rm, and for important folders keep backups or use a version control system.

Practise with interview questions