RousselTMLEARNING

Automation

Linux vs Unix: the complete guide to commands and distributions

Understand the differences between Linux and Unix, explore distributions (server, desktop, lightweight), security (SELinux, AppArmor) and systemd, and master the essential commands.

1. Linux vs Unix: the origins of a giant #

Understanding the lineage and fundamental differences between the historical Unix operating system and its open source descendant, Linux.

What is Unix? #

Unix is a multi-user, multitasking operating system (OS) developed in the 1970s at AT&T's Bell Labs. It introduced revolutionary concepts such as the hierarchical file system and the 'small tools' philosophy (each program does one thing and does it well). Unix is a proprietary standard; systems such as macOS, AIX (IBM) or Solaris (Oracle) are certified Unix descendants.

What is Linux? #

Linux is actually the name of the kernel created by Linus Torvalds in 1991. It was designed as a free, open source alternative to the Unix kernel. A complete operating system based on the Linux kernel is called a GNU/Linux distribution, because it combines the Linux kernel with the tools and utilities of the GNU project (such as the Bash shell).

Table of key differences #

CriterionUnixLinux
LicenseProprietary, closed sourceOpen source (GPL)
CostUsually paid and tied to hardwareFree (except for versions with commercial support)
PortabilityLimited to specific architecturesExtremely portable (from servers to smartphones)
EcosystemControlled by a single vendorCommunity-driven, with thousands of contributors

In short, Linux is not Unix, but a 'Unix-like' system that follows its philosophy and standards (POSIX).

2. The world of Linux distributions #

A Linux distribution is a complete operating system assembled around the Linux kernel. It includes a package manager, desktop environments and a selection of software.

Free vs paid distributions #

The difference is not the cost of the software itself (which remains open source), but commercial support.

  • Free (community): developed and maintained by a community. Support is provided through forums and mailing lists. Examples: Debian, Ubuntu, Fedora, Arch Linux.
  • Paid (commercial): offer support contracts, stability guarantees, certifications and extended life cycles, which are essential for companies. Examples: Red Hat Enterprise Linux (RHEL), SUSE Linux Enterprise Server (SLES).

The major families of distributions #

Distributions are often grouped into families based on their package management system.

FamilyPackage managerNotable distributions
Debian logoDebianapt / dpkg (.deb files)Debian, Ubuntu, Linux Mint
Red Hat logoRed Hatdnf / yum / rpm (.rpm files)Fedora, Red Hat Enterprise Linux (RHEL), CentOS Stream, Rocky Linux
Arch Linux logoArchpacmanArch Linux, Manjaro
openSUSE logoSUSEzypperopenSUSE, SLES

Server vs desktop #

Most major distributions offer versions optimized for two main uses:

  • Desktop version: designed for personal computers. It includes a graphical interface (a desktop environment such as GNOME, KDE or XFCE), office software, web browsers and multimedia tools. The focus is on ease of use and user experience. Examples: Ubuntu Desktop, Fedora Workstation, Linux Mint.
  • Server version: optimized to host services (web, databases, etc.). It usually has no graphical interface by default, to save resources. Long-term stability, security and performance are the priorities. Examples: Ubuntu Server, Debian, RHEL.

Full vs lightweight (for containerization) #

In the world of containerization (with Docker for example), lightness is king. A container image must be as small as possible to speed up deployments and reduce the attack surface.

  • Full distributions: a standard installation (even a server one) includes many tools, documentation and services that are useless in a container.
  • 'Lightweight' distributions: minimal versions were created specifically for containers. They contain only what is strictly necessary to run an application. The most famous example is Alpine Linux, which is based on `musl libc` and `BusyBox`, and whose base image weighs only a few megabytes.

3. Security: SELinux and AppArmor #

Linux includes advanced security modules (LSM) to strengthen access control beyond traditional permissions.

SELinux (Security-Enhanced Linux) #

Originally developed by the NSA, SELinux is a mandatory access control (MAC) system mainly used by Red Hat family distributions (RHEL, Fedora, CentOS). It works based on security policies that define precisely what each process is allowed to do. Even a `root` process can be blocked by SELinux.

Basic commands:

  • Check the SELinux status:
    sestatus
    Example output of the sestatus command
  • Change the mode (temporarily):
    • sudo setenforce 1: `Enforcing` mode (blocks unauthorized actions).
    • sudo setenforce 0: `Permissive` mode (logs unauthorized actions but does not block them).
  • Change a file's context: if a web server cannot read a file because of SELinux, it is often a context problem. You can fix it with `chcon`.
    # Donner le contexte httpd_sys_content_t à un fichier pour qu'Apache puisse le lire
    sudo chcon -t httpd_sys_content_t /var/www/html/index.html

AppArmor (Application Armor) #

AppArmor is the alternative to SELinux, used by default in Debian family distributions (Debian, Ubuntu). It is considered simpler to administer. AppArmor attaches a security profile to each application, listing the allowed files and permissions.

Basic commands:

  • Check the AppArmor status:
    sudo aa-status
  • Example (simplified) profile for `/usr/bin/ping`: an AppArmor profile is a text file that defines permissions. Here is an excerpt:
    # /etc/apparmor.d/usr.bin.ping
    
    profile /usr/bin/ping flags=(attach_disconnected) {
      #include <abstractions/base>
      
      # Autorise la lecture du binaire ping lui-même
      /bin/ping r,
      
      # Autorise l'utilisation des capacités réseau nécessaires pour ping
      capability net_raw,
      capability setuid,
    
      # ... autres règles
    }
    This profile ensures the `ping` program can only do what it is designed for, and nothing else.

4. Managing services: systemd and systemctl #

Understanding the role of Linux's modern init system and how to interact with it.

What is systemd? #

systemd is the init system and service manager used by the vast majority of modern Linux distributions. It is the first process started at boot (with PID 1) and is responsible for starting all other services (network, SSH, database, etc.) in parallel and efficiently.

The role of systemctl #

systemctl is the main command-line tool to interact with `systemd`. It lets administrators manage systemd 'units' (mainly services, but also mount points, timers, etc.).

Here are the most common `systemctl` commands for a service named `nginx.service`:

  • Start a service:
    sudo systemctl start nginx
  • Stop a service:
    sudo systemctl stop nginx
  • Restart a service:
    sudo systemctl restart nginx
  • Reload the configuration without stopping the service:
    sudo systemctl reload nginx
  • Check a service's status (active, inactive, errors):
    systemctl status nginx
    Example output of systemctl status
  • Enable a service at system startup:
    sudo systemctl enable nginx
  • Disable a service at startup:
    sudo systemctl disable nginx

5. The essential commands to know #

Mastering the command line is essential for any system administrator. Here is a selection of the most useful commands. Most commands also share common options such as `--help` to display help or `--version` to show their version.

Understanding options and parameters #

Most Linux commands accept options (also called flags or switches) that change their behavior. There are two formats:

  • Short options: preceded by a single dash (-), they consist of a single letter (e.g. -l). They can be combined: ls -l -a is equivalent to ls -la.
  • Long options: preceded by two dashes (--), they are more descriptive (e.g. --all). They cannot be combined.

A parameter (or argument) is a piece of information passed to the command, such as a file or directory name (e.g. /var/log in cd /var/log).

Navigation and file management #

  • ls: list the contents of a directory.
    Structure: ls [OPTIONS] [PATH]
    Required: the command itself. The PATH is optional (by default, the current directory).
    # Lister les fichiers avec détails (permissions, taille, date)
    ls -l
    
    # Lister tous les fichiers, y compris les fichiers cachés
    ls -la
    
    # Lister le contenu d'un répertoire spécifique
    ls /var/log
  • cd: change directory.
    Structure: cd [PATH]
    Required: the command itself. If no PATH is given, the command goes to the user's home directory.
    # Aller à un chemin spécifique
    cd /var/log
    
    # Aller au répertoire personnel
    cd
    
    # Remonter d'un niveau
    cd ..
    
    # Aller au répertoire précédent
    cd -
  • pwd: print the path of the current directory.
    Structure: pwd
    Required: the command usually takes no argument.
    # Affiche le chemin complet du répertoire où vous vous trouvez
    pwd
  • cp: copy files or directories.
    Structure: cp [OPTIONS] SOURCE DESTINATION
    Required: the SOURCE (what you copy) and the DESTINATION (where you copy it).
    # Copier un fichier
    cp source.txt destination.txt
    
    # Copier un répertoire récursivement (indispensable pour les dossiers)
    cp -r /mon/repertoire /ma/destination
    
    # Copier avec une barre de progression (nécessite 'rsync' ou 'pv')
    # Alternative simple : copier en mode verbeux
    cp -v mon_gros_fichier.zip /mnt/backup/
  • mv: move or rename a file/directory.
    Structure: mv [OPTIONS] SOURCE DESTINATION
    Required: the SOURCE and the DESTINATION. The behavior (move or rename) depends on the destination.
    # Renommer un fichier (la destination est un nouveau nom dans le même répertoire)
    mv ancien_nom.txt nouveau_nom.txt
    
    # Déplacer un fichier (la destination est un répertoire)
    mv mon_fichier.txt /autre/repertoire/
  • rm: delete files or directories.
    Structure: rm [OPTIONS] FILE...
    Required: the name of the FILE(s) to delete. Be extremely careful with this command.
    # Supprimer un fichier (demande souvent confirmation)
    rm mon_fichier.txt
    
    # Forcer la suppression sans confirmation
    rm -f mon_fichier.txt
    
    # Supprimer un répertoire et son contenu récursivement (TRÈS DANGEREUX)
    rm -rf /mon/repertoire
  • mkdir: create a directory.
    Structure: mkdir [OPTIONS] DIRECTORY_NAME...
    Required: the name of the directory to create.
    # Créer un répertoire simple
    mkdir mon_dossier
    
    # Créer des répertoires parents s'ils n'existent pas
    mkdir -p /chemin/vers/nouveau/dossier

Searching and manipulating text #

  • grep: search for a pattern in text or a file.
    Structure: grep [OPTIONS] PATTERN [FILE...]
    Required: the PATTERN to search for. If no FILE is specified, grep reads standard input (useful with pipes |).
    # Rechercher 'error' dans un fichier de log (insensible à la casse)
    grep -i 'error' /var/log/app.log
    
    # Compter le nombre de lignes contenant 'error'
    grep -c 'error' /var/log/app.log
    
    # Afficher les 5 lignes après une correspondance
    grep -A 5 'error' /var/log/app.log
    
    # Utiliser avec un pipe pour filtrer la sortie d'une autre commande
    ps aux | grep 'nginx'
  • find: search for files and directories.
    Structure: find [PATH] [EXPRESSION]
    Required: the starting PATH of the search (e.g. . for the current directory) and a test EXPRESSION (e.g. -name "*.log").
    # Trouver tous les fichiers .log dans le répertoire courant
    find . -name "*.log"
    
    # Trouver les répertoires (type d) uniquement
    find /home -type d -name "images"
    
    # Trouver les fichiers modifiés il y a moins de 24h
    find . -mtime -1
    
    # Exécuter une commande sur les fichiers trouvés (ici, les supprimer)
    find . -name "*.tmp" -exec rm {} \;
  • cat: display the contents of a file. Ideal for short files.
    Structure: cat [FILE...]
    Required: the name of the file to display.
    # Afficher les informations sur la distribution Linux
    cat /etc/os-release
    
    # Concaténer deux fichiers et rediriger la sortie vers un troisième
    cat fichier1.txt fichier2.txt > fichier_combine.txt
  • less / more: display the contents of a file page by page. `less` is more modern and lets you navigate forward and backward.
    Structure: less [FILE]
    Required: the name of the file to browse.
    # Parcourir un long fichier de log (quitter avec la touche 'q')
    less /var/log/syslog
  • head / tail: display the beginning or end of a file.
    Structure: tail [OPTIONS] [FILE]
    Required: the file name.
    # Afficher les 20 premières lignes d'un fichier
    head -n 20 /var/log/syslog
    
    # Afficher les 10 dernières lignes d'un log en temps réel
    tail -f /var/log/syslog

Users and groups #

In a Linux system, managing users and groups is fundamental for security and organizing permissions. Every file and process is associated with a user and a group, which determines who can access it and what actions can be performed.

  • User: represents an individual entity (person or service) that interacts with the system. Each user has a unique identifier (UID) and a home directory.
  • Group: a collection of users. Permissions can be assigned to a group, which simplifies access management for several users with the same needs. Each group has a unique identifier (GID).

Users can belong to several groups. A primary group is assigned to the user at creation, and they can be a member of secondary groups.

  • id: displays a user's identifiers (user and group).
    Structure: id [OPTIONS] [USER]
    Required: the command itself. If no user is specified, it shows the current user's information.
    # Afficher les informations de l'utilisateur courant
    id
    
    # Afficher uniquement l'UID
    id -u
    
    # Afficher les informations d'un autre utilisateur
    id www-data
  • useradd: creates a new user.
    Structure: useradd [OPTIONS] LOGIN
    Required: the name of the user (LOGIN) to create. Often used with -m to create the home directory.
    # Créer un utilisateur 'newuser' avec son répertoire personnel
    sudo useradd -m newuser
    
    # Créer un utilisateur de service sans shell de connexion
    sudo useradd -r -s /bin/false appuser
    
    # Créer un utilisateur et l'ajouter à des groupes secondaires
    sudo useradd -m -G wheel,docker devuser

    Note: on Debian/Ubuntu systems, the adduser command is a friendlier interactive script that uses useradd behind the scenes.

  • usermod: modifies an existing user.
    Structure: usermod [OPTIONS] LOGIN
    Required: the user name (LOGIN) and the modification options.
    # Ajouter un utilisateur au groupe 'sudo' (pour les droits admin)
    sudo usermod -aG sudo martin
    
    # Changer le shell par défaut d'un utilisateur
    sudo usermod -s /bin/zsh martin
    
    # Verrouiller le compte d'un utilisateur
    sudo usermod -L martin
  • userdel: deletes a user.
    Structure: userdel [OPTIONS] LOGIN
    Required: the name of the user (LOGIN) to delete.
    # Supprimer un utilisateur sans supprimer son répertoire personnel
    sudo userdel olduser
    
    # Supprimer un utilisateur ET son répertoire personnel
    sudo userdel -r olduser
  • groupadd: creates a new group.
    Structure: groupadd [OPTIONS] GROUP
    Required: the name of the GROUP to create.
    # Créer un groupe 'developers'
    sudo groupadd developers

Managing permissions #

  • chmod: change the permissions of a file/directory.
    Structure: chmod [MODE] FILE
    Required: the MODE (octal notation such as 755 or symbolic such as u+x) and the target FILE.
    # Donner les droits d'exécution au propriétaire
    chmod u+x mon_script.sh
    
    # Utiliser la notation octale (r=4, w=2, x=1)
    # 7 (rwx) pour le propriétaire, 5 (r-x) pour le groupe, 5 (r-x) pour les autres
    chmod 755 mon_script.sh
    
    # Appliquer des permissions récursivement à un répertoire
    chmod -R 644 /var/www/html
  • chown: change the owner and group of a file/directory.
    Structure: chown [OWNER]:[GROUP] FILE
    Required: the new OWNER and the FILE. The group is optional.
    # Changer le propriétaire et le groupe
    chown www-data:www-data mon_fichier.txt
    
    # Changer uniquement le propriétaire
    chown martin mon_fichier.txt
    
    # Appliquer récursivement à un répertoire
    chown -R www-data:www-data /var/www/html

Managing processes #

  • ps: list running processes.
    Structure: ps [OPTIONS]
    Required: the command itself. The options determine the output format.
    # Afficher tous les processus de tous les utilisateurs avec détails
    ps aux
    
    # Afficher une arborescence des processus
    ps axjf
    
    # Filtrer pour trouver un processus spécifique (ex: nginx)
    ps aux | grep nginx
  • kill: send a signal to a process (often to terminate it).
    Structure: kill [SIGNAL] PID
    Required: the PID (process ID) of the target process. The signal is optional (by default -15, or TERM).
    # Terminer proprement un processus (signal TERM)
    kill 12345
    
    # Forcer la terminaison d'un processus (signal KILL)
    kill -9 12345
    
    # Envoyer un signal pour recharger la configuration (SIGHUP)
    kill -1 6789
  • top / htop: interactive process monitor. `top` is preinstalled everywhere. `htop` is an improved, more visual and easier-to-use version (it often needs to be installed: `sudo apt install htop`).
    Structure: top or htop
    Required: the command runs without arguments.

    Example of htop

Network and connectivity #

  • ssh: connect securely to a remote machine.
    Structure: ssh [USER]@[HOST]
    Required: the HOST (IP address or domain name). The user is optional (by default, the current user).
    # Connexion avec un utilisateur spécifique
    ssh martin@192.168.1.100
    
    # Connexion sur un port différent (ex: 2222)
    ssh -p 2222 martin@serveur.com
  • scp: copy files securely over SSH.
    Structure: scp [SOURCE] [DESTINATION]
    Required: the SOURCE and the DESTINATION. One of the two must be remote, in the format user@host:/path.
    # Copier un fichier local vers une machine distante
    scp mon_fichier.txt martin@hote:/home/martin/
    
    # Copier un fichier distant vers la machine locale
    scp martin@hote:/var/log/app.log .
  • ping: test network connectivity with a host by sending ICMP packets.
    Structure: ping [OPTIONS] HOST
    Required: the HOST to test.
    # Envoyer 4 paquets de test à google.com
    ping -c 4 google.com
  • curl: a powerful tool to transfer data with URLs. It is widely used to interact with REST APIs.
    Structure: curl [OPTIONS] URL
    Required: the URL of the resource to query.
    # Afficher uniquement les en-têtes de réponse HTTP
    curl -I http://api.example.com/status
    
    # Envoyer une requête POST avec des données JSON
    curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' http://api.example.com/data

    curl vs grpcurl: while curl is the standard for REST APIs (based on HTTP), grpcurl is its equivalent for gRPC APIs. It lets you interact with gRPC servers from the command line, without having to generate a specific client.

    To install it, follow these steps:

    # Télécharger la dernière version (exemple v1.9.3)
    curl -sSL https://github.com/fullstorydev/grpcurl/releases/download/v1.9.3/grpcurl_1.9.3_linux_x86_64.tar.gz | tar -xz
    
    # Déplacer le binaire dans le PATH
    sudo mv grpcurl /usr/local/bin/
  • wget: a simple utility to download files from the web. It is less interactive than curl but excellent for direct downloads.
    Structure: wget [OPTIONS] URL
    Required: the URL of the file to download.
    # Télécharger un fichier
    wget https://example.com/fichier.zip
    
    # Télécharger un fichier et le renommer
    wget -O mon_archive.zip https://example.com/fichier.zip

6. Conclusion #

Linux is a vast, powerful ecosystem. Mastering these basic concepts and commands is the essential first step to becoming a competent administrator or developer in this environment.

Related articles

The LGTM stack (Loki, Grafana, Tempo, Mimir): architecture and setup

Grafana Labs' LGTM stack: Loki for logs, Grafana for visualization, Tempo for traces, Mimir for metrics (and …

Grafana Tempo: the distributed tracing backend at scale

Understand distributed tracing and Grafana Tempo: traces, spans, TraceID, architecture (distributor, ingester…

Installing Grafana Tempo (Docker Compose, binary and Helm)

Install Grafana Tempo: the tempo.yaml configuration, Docker Compose with Grafana and Prometheus, OTLP ports, …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!