Basic Linux commands explained in detail

Last update: April 14th 2026
  • Learn to navigate the file system with ls, cd and pwd and manage folders with mkdir, rm and cp.
  • Master viewing and searching in text files using cat, less, grep, sed, awk, and find.
  • Control permissions, processes and network with chmod, chown, ps, top, htop, ping, ip and ss in server environments.
  • Install and update software with apt, use tar/zip, wget and scp, and automate tasks by combining commands and redirects.
basic linux commands

If you work with servers, web development, or simply want to get the most out of your PC , sooner or later you'll end up in the Linux terminal. And there, you either know the basic commands, or you'll be staring at the blinking cursor, unsure of what to do. The good news is that you don't need to memorize hundreds of commands: mastering a solid set of commands will cover 90% of your daily tasks.

In this guide you will find a unified and very complete compilation of basic Linux commands , mixing the best of several reference guides: file management, processes, network, packages, permissions, automation… All explained in Spanish (Spain), with real examples of server administration, hosting and local work, and organized so that you can use it as a cheat sheet when you need it.

basic linux commands

What are Linux commands and why do they matter so much?

A Linux command is a program or utility that runs from the command line . Instead of clicking buttons, you type the command name, optionally some options (or flags) , and one or more arguments such as file paths, patterns, or service names.

The idea is simple: the terminal is a very efficient text interface . One-click execution is fine, but chaining commands, automating backups with cron, reviewing huge logs with filters, or managing a remote server via SSH is infinitely more convenient by typing a few commands than by struggling with graphical menus.

In almost any modern distribution (Ubuntu, Debian, CentOS, Fedora, Arch, etc.) you'll open a terminal with Ctrl+Alt+T or by searching for "Terminal" in the applications menu. On a server, you'll typically access it via SSH from your local machine.

Essential directory navigation commands

The first thing you need to master is how to navigate the file system : knowing where you are, what's in each location, and how to quickly switch folders.

ls: list files and directories

The `ls` command displays the contents of the current directory (or the path you specify). It's one of the commands you'll use most often.

  • ls – Lists visible files and folders in the current directory.
  • ls -l – Shows details: permissions, owner, size, date.
  • ls -a – Includes hidden files (those that begin with a period).
  • ls -lh – Just like -lbut with legible sizes (K, M, G).
  • ls -lah – Combines long, hidden, and legible sizes.
  • ls -R – Recursive listing of subdirectories.
  • ls -t – Sort by modification date.
  • ls -S – Sort by size.

On web servers it's common to do something like ls -lah /var/www/html to view all project files, including hidden configuration files , the .htaccess or the folder .git.

pwd: know which folder you are in

When you've been hopping between routes for a while, it's very easy to get lost. With pwd (print working directory) you get the full path of the current directory, For example:

/home/usuario/proyectos/mi-sitio

It is especially useful in scripts , when you need to know where you are to work with relative paths safely.

cd: change directory

To navigate the file system, you use cd (change directory). Some essential variations:

  • cd /ruta/completa – It's going down an absolute route.
  • cd carpeta – Enter a folder relative to the current directory.
  • cd ~ – Jump to personal directory of user.
  • cd - – Return to the previous directory (very useful, it seems silly until you use it).
  • cd .. – Move up one level in the hierarchy.
  • cd ../.. – Go up two levels, and so on.

If you work with Linux hosting, you'll get tired of using cd /var/www/html or similar paths to access your website's root directory.

Basic file and directory commands

Once you've mastered navigating the system, it's time to learn how to create, copy, delete, and view files and folders . This is essential for everyday tasks on both PCs and VPSs.

mkdir and rmdir: creating and deleting empty directories

With mkdir You create new folders. It supports multiple paths at once and has very practical options:

  • mkdir nuevo_directorio – Create a simple folder.
  • mkdir dir1 dir2 – Create several at once.
  • mkdir -p padre/hijo/nieto – Create a complete nested structure, without complaining if part of it already exists.
  • mkdir -m 755 carpeta_web – Create the folder with specific permissions.

A typical pattern when setting up a project is something like this: mkdir -p /var/www/mi-sitio/{public_html,logs,backups} to get everything organized from minute one.

To delete empty directories, there is rmdir:

  • rmdir carpeta_vacia – Delete a folder as long as it doesn't contain anything.
  • rmdir -p dir1/dir2/dir3 – Remove the entire chain if all levels are empty.

If the directory has content, you will need to use rm -rwhich we will see shortly.

touch: create empty files or update dates

The command touch It is mainly used for create empty files or update the modification date without touching its content:

  • touch archivo.txt – Create the file if it does not exist.
  • touch archivo1 archivo2 – Create several at once.
  • touch -t 202501010000 archivo.txt – Force a specific timestamp.

It's very convenient for generating configuration files or placeholders type touch .env o touch index.html.

rm: carefully delete files (and directories)

With rm You delete files and, with the right options, directory trees. There is no trash canIf you make a mistake, recovering something can be complicated or impossible.

  • rm archivo.txt – Delete a file.
  • rm archivo1 archivo2 – Delete several.
  • rm -i archivo.txt – Ask for confirmation, ideal while you're learning.
  • rm -r carpeta – Recursively deletes a folder and all its contents.
  • rm -rf carpeta – Force recursive deletion without asking; Use it only when you are absolutely sure what you are doing..
  • rm *.tmp – Delete all files with that extension in the current directory.
  AtlasOS vs ReviOS: real differences, risks, and what to choose

Combinations like rm -rf / or similar are quick fixes for rendering a system unusable, so Be careful when mixing RM and RF with general or wildcard routes..

cp and mv: copy, move and rename

To duplicate files you use cp And to move or rename you use mvBetween the two of you, you can handle any file reorganization.

Some typical uses of cp :

  • cp origen.txt destino.txt – Copy a file.
  • cp archivo.txt /otra/ruta/ – Copy to another directory.
  • cp -i archivo.txt copia.txt – Ask before you pound.
  • cp -p archivo.txt backup.txt – Keep permits, owner and date.
  • cp -r carpeta_origen carpeta_destino – Recursive copying of a directory.

For complete copies of websites, something like this is very common. cp -rp /var/www/html /backup/html-$(date +%Y%m%d), which leaves a dated backup maintaining permissions and ownership.

With mv you can both move and rename:

  • mv archivo.txt nuevo_nombre.txt – Rename.
  • mv archivo.txt /otra/ruta/ – Move it.
  • mv directorio nuevo_nombre – Rename a folder.
  • mv *.log /var/log/backups/ – Relocate all logs.

A commonly used pattern when deploying projects is mv sitio-nuevo/* /var/www/html/ to replace the old version of the website with the new one.

cat, less, head and tail: view file contents

To inspect the contents of a text file, you have several tools, each with its own advantages.

  • cat archivo.txt Displays the entire file in the terminal. Ideal for small files or concatenate several: cat archivo1 archivo2.
  • less archivo.log It serves for large filesbecause it lets you navigate page by page, search (/texto), go back and forth and exit with q.
  • head archivo It displays the first 10 lines by default; with head -n 50 You choose how many.
  • tail archivo It shows the last lines; with tail -f archivo.log You can see how the log is updated in real time, very useful while you are reproducing an error on the website.

In web server debugging you will constantly see combinations like tail -f /var/log/nginx/error.log o less /var/log/apache2/access.log to understand what is happening.

Commands for searching files and text

As the system grows and becomes filled with projects, logs, and configurations, knowing how to quickly locate files and text strings becomes key.

find and locate: search for files by name, size, or date

The command find It scans the file system and allows you to search by name, type, size, modification date, etc., and even take action on the results:

  • find /ruta -name "nombre_archivo" – Search by exact name.
  • find /var/www -name "*.php" – Locate all PHP files in that area.
  • find /home -type f -size +100M – Files larger than 100 MB.
  • find /var/log -mtime -7 – Files modified in the last 7 days.
  • find . -name "*.tmp" -delete – Search for and delete temporary files.
  • find /var/www -type f -exec chmod 644 {} \; – Adjust permissions for all files.

For its part, locate pull of one indexed databaseTherefore, it is much faster for simple name searches:

  • locate nombre_archivo
  • locate -i "*.php" – Ignores uppercase/lowercase.
  • sudo updatedb – Update the index (important on servers).

The problem with locate is that it doesn't see newly created files until the database is updated, whereas find always looks at the actual system.

grep, sed and awk: search, filter and transform text

For working with logs, configurations, or any plain text, the best are grep, sed y awk.

  • grep Look for lines that match a pattern:
    grep "ERROR" /var/log/apache2/error.log
    grep -i "texto" archivo.txt – Ignore capital letters.
    grep -r "cadena" /directorio – Recursive search.
    grep -n "texto" archivo.txt – Show line number.
  • thirst allow replace or delete text without opening the file in an editor:
    sed 's/viejo/nuevo/g' archivo.txt – Replace all occurrences.
    sed -i 's/old_database/new_database/g' wp-config.php – Edit in place (be very careful with this).
  • awk it's perfect for process columns (for example, logs):
    awk '{print $1}' access.log – Extract the first column (typically IP).
    awk '{print $1}' access.log | sort | uniq -c | sort -nr | head -10 – Your 10 most active IPs.

Although they may seem intimidating at first, once you get the hang of these tools you can perform analyses in seconds that would be a nightmare in an editor.

Management of permissions, owners and basic security

Linux is based on a very clear permissions system that allows you to control who can read, write, or execute what . This is critical in multi-user environments and, especially, on web servers.

ls -l: see permissions and owners

We've already mentioned it, but it's worth emphasizing: ls -l It teaches you, in addition to file names, the permissions, owner, group, and sizeA typical example:

-rw-r--r-- 1 usuario grupo 12345 Jan 1 12:34 archivo.txt
drwxr-xr-x 2 usuario grupo 4096 Jan 1 12:34 carpeta/

The first column reads as follows: type (- archive, d directory) and then three sets of permissions: user, group, and others (r reading, w writing, x execution).

chmod: change permissions

With chmod You adjust the permissions of a file or folder. You can do this with numerical notation o symbolic:

  • chmod 755 script.sh – rwxr-xr-x (owner of everything, the rest read/execute only).
  • chmod 644 index.html – rw-r–r–, very common for web files.
  • chmod u+x backup.sh – Add execution to the user.
  • chmod g-w archivo.txt – Remove writing from the group.
  • chmod -R 755 directorio – Change permissions recursively.

The numerical values ​​are added together: 4 read, 2 write, 1 execute . That's why 7 = 4+2+1 (rwx), 6 = 4+2 (rw-), 5 = 4+1 (rx), etc.

chown and chgrp: owner and group

In addition to permissions, each file has an owner and an associated group . This allows you to ensure, for example, that the web server owns the files it needs to serve.

  • chown usuario archivo.txt – Change of owner.
  • chown usuario:grupo archivo.txt – Change owner and group.
  • chown -R www-data:www-data /var/www/html – Typical on Apache/Nginx servers on Debian/Ubuntu.
  • chgrp grupo archivo.txt – Only change the group.
  What is FTP?: A Complete Guide

When you upload files via FTP with one user and then the web server (another user) cannot read or write them, you can almost always fix it with a well-placed chown or chmod.

sudo: run as administrator without being root

The command sudo (superuser do) is the recommended way to run administrative tasks without logging in directly as root, which is dangerous.

Simply precede the command you want to execute with elevated privileges with `sudo` :

  • sudo apt update – Update the package list (Debian/Ubuntu).
  • sudo systemctl restart nginx – Restart Nginx.
  • sudo useradd nuevo_usuario – Create a user.

It will ask for your password, and if your user account is in the correct group, you will execute the command with root privileges. This prevents you from being logged in as root all the time, which could accidentally delete or modify critical files.

Process management and system performance

When something is slow or acting strangely, you need to look at which processes are running and how they're using resources . These commands are your best friends for that.

ps, top, and htop: see what's running

The command ps Take a photograph of the processes active at that moment. ps aux You see all system processes, including user activity, CPU and RAM usage, etc. You can filter with grep:

  • ps aux | grep nginx – View only Nginx processes.
  • ps -u usuario – Processes of a specific user.

If you want something dynamic, real-time, you use top or its vitamin-enhanced version htop:

  • top – Lists processes ordered by CPU usage and is updated.
  • Within top you can sort by memory (M), kill processes (k), Etc.
  • htop – Same but with colors, CPU bars, mouse support, process tree… on many systems it needs to be installed first (sudo apt install htop or similar).

On a slow server, opening htop is usually the first step to see what's eating up the CPU or RAM.

kill and killall: terminate rogue processes

If a process hangs or fires and doesn't respond, you can stop it with kill o killall.

  • kill 1234 – Send the TERM (15) signal to the process with PID 1234, asking it to terminate “quietly”.
  • kill -9 1234 – KILL signal (9), kills the process immediately; use it as a last resort.
  • killall nombre_proceso – Terminate all processes that have that name, for example killall php-fpm.

The usual way to locate the PID is with ps o top and then pass it a kill Gently. If it doesn't obey, then you pull the -9.

df and du: controlling disk space

When a server runs out of space, everything starts to go wrongDatabases that can't be written to, logs that aren't growing, services that keep crashing. To monitor this, you use df y du.

  • df -h – Shows used and free space on each mounted file system, in a readable format.
  • df -h /var – Information only from that partition.
  • du -sh /var/www/* – Size of each web project within that route.
  • du -h --max-depth=1 / – Which root directories take up the most space.

A very practical command for locating the heaviest folders It's something like du -h --max-depth=1 /var | sort -hr | head -5, which lists the five largest ones ordered from largest to smallest.

Essential network commands

When you work with servers, domains, and web traffic, you need to know if there is connectivity, what IP you have, what ports are open, and how your site responds.

ip, ifconfig, ping and route

Modern systems, the star command is ip, Especially ip a (o ip addr), which displays all network interfaces, their IPs, status, etc. Where previously it was used ifconfigToday it is recommended ip, although ifconfig It still exists in many systems via package net-tools.

  • ip a – All interfaces and IPs.
  • ip addr show dev eth0 – Details of a specific interface.
  • ping google.com – Check if you solve and reach Google, showing times.
  • ping -c 4 8.8.8.8 – Send only 4 packets to that IP.
  • route -n o ip route show – Route table, to see where the traffic is coming from.

If a server "is not visible", the first steps are always Ping the domain, ping the IP address, look at the server's IP address and its gateway. with ip route.

netstat/ss and curl: open ports and HTTP response

To see what Which ports are open and what processes are listening? In them, you have netstat (classic) and ss (modern, faster):

  • ss -tuln – TCP/UDP ports listening without resolving names.
  • ss -tlnp | grep :80 – Is there anything listening at port 80?
  • netstat -tuln – Equivalent in systems that have it.

For quick testing how a website responds from the server itself, nothing like curl:

  • curl -I https://tu-dominio.com – Only HTTP headers (status code, server, etc.).
  • curl https://tu-dominio.com – Download the raw HTML.

By combining ping, ip, ss, and curl, you can diagnose almost any basic connectivity or service outage problem.

Package management: installing, updating, and cleaning software

Each Linux distribution family has its own package manager . Mastering it allows you to install and update software without struggling with manual binaries.

apt and apt-get in Debian/Ubuntu

In Debian, Ubuntu and derivatives, the standard is apt (or its classic version) apt-get):

  • sudo apt update – Update the list of available packages.
  • sudo apt upgrade – Update all installed packages to the latest version.
  • sudo apt install nombre_paquete – Install one or more packages.
  • sudo apt remove nombre_paquete – Uninstall the package but leave its configuration.
  • sudo apt purge nombre_paquete – It erases everything, including the settings.
  • sudo apt autoremove – Remove dependencies that are no longer used.
  Changes and new features in Windows 11 that you should know about

You also have apt-cache or directly apt show all with View package information, its dependencies and versions:

  • apt show nginx
  • apt search php

yum/dnf and pacman: other families

On Red Hat-based systems like CentOS or RHEL you will have yum or its successor dnf:

  • sudo yum install httpd – Install Apache.
  • sudo dnf update – Update everything to newer versions.

In Arch Linux and derivatives, the manager is pacman:

  • sudo pacman -S gimp – Install GIMP.
  • sudo pacman -Syu – Synchronize and update the system.

Although the syntax changes, the philosophy is the same : update indexes, install packages, remove them, and clean up leftover dependencies.

Compress, decompress, and transfer files

Managing large files or sets of files is greatly simplified with compressed files and with remote download and copy utilities.

tar, zip/unzip: packaging and compression

The command tar It is the standard in Linux for creating and extracting tarballs (files .tar, .tar.gz, .tar.bz2, etc.):

  • tar -czvf backup.tar.gz carpeta/ – Create a .tar.gz file compressed with gzip.
  • tar -xzvf backup.tar.gz – Extract the content.
  • tar -tzvf backup.tar.gz – List what's inside without removing it.

The most common flags are c (create), x (extract), t (list), v (verbose), f (file), z (gzip), j (bzip2), J (xz).

To work with ZIP files (very common in Windows environments) you have zip y unzip:

  • zip archivo.zip fichero1 fichero2
  • unzip archivo.zip

wget, curl and scp: download and copy between machines

Besides browsing with curl, you can use wget To download files from HTTP or FTP:

  • wget https://wordpress.org/latest.zip – Download the latest version of WordPress.
  • wget -c URL – Resume an interrupted download.

To securely copy files between your computer and a server via SSH you have scp:

  • scp archivo.txt usuario@servidor:/ruta/destino/ – Upload a file.
  • scp -r carpeta usuario@servidor:/ruta/ – Recursively copies a folder.
  • scp usuario@servidor:/ruta/archivo.txt ./ – Download from the server.

Behind all of this is SSH, which is also what you use to connect to the remote terminal (command ssh usuario@servidor).

Automation, history, and small productivity tricks

Once you've mastered the basics, the next step is to start combining commands and automating repetitive tasks . This is where Linux truly shines.

history, alias and which: shortcuts and quick references

With history You can see the last commands you executed and reuse them without rewriting them:

  • history – List with line number.
  • !255 – Run command number 255 again.

To create temporary shortcuts is alias:

  • alias ll="ls -lah" – From here ll equivalent to ls -lah.
  • unalias ll – Remove the alias.

And if you want to know where a program is installed And what executable is being called, are you using? which:

  • which php – Show the path to PHP, for example /usr/bin/php.
  • which -a python – All matches in the PATH.

Redirections and pipes: combining commands like a pro

The true power of the command line comes from power chain small toolsThis is done with pipelines (|) and redirects (>, >>, 2>, etc.).

  • comando1 | comando2 – The exit of comando1 enters as an entry in comando2.
    Example: ls -la | grep ".php" – List only files that contain “.php”.
  • ls > listado.txt – Save the output to a file (overwrite).
  • echo "línea" >> archivo.txt – Add to the end of a file.
  • comando > todo.log 2>&1 – Redirects normal output and errors to the same file.
  • comando &> /dev/null – Send everything to the “black hole”.

With this you can do amazing things, like count 404 errors in a log with a command like grep " 404 " access.log | wc -l, clean up old files with find y -delete.

If you've made it this far, you already have a fairly complete map of the basic (and not so basic) Linux commands used daily in system administration, development, and hosting: from navigating directories, managing files, permissions, and processes, to monitoring the network, installing packages, and automating tasks by combining commands with pipes and redirects; from now on, every time you open a terminal, it will no longer be an intimidating black screen but a tool that allows you to work faster and with more control than any graphical interface.