debian wiki

Terminal Guide

Basic commands for new Linux users (Applicable to Debian-based distributions like Ubuntu, Linux Mint, Pop!_OS...)

Introduction

Welcome to the world of the terminal. In this guide, you will learn the fundamental commands to navigate Linux smoothly from the command line. Mastering the terminal is not mandatory for daily use: distributions like Ubuntu or KDE Plasma offer very comprehensive graphical environments with software stores, update managers, and visual tools. However, the terminal offers a power, speed, and flexibility that no graphical interface can match. Once you get used to it, you will discover that many tasks can be resolved in seconds with a single command.

💡 Tip: Do not memorize all the commands at once. Practice a little bit at a time, a couple of commands a day, and in a few weeks, they will become natural to you.

1. System Management with APT

APT (Advanced Package Tool) is the package manager for Debian and its variants. With it, you can update the system, install and uninstall software, and much more. You will almost always need to prepend sudo to execute these commands with administrator privileges.

1.1 Update the system

Updating the system is an important habit to maintain security and stability. The process is done in two steps:

Step 1: Update the list of available packages.

user@debian:~$ sudo apt update

This command does not download or install anything yet; it simply queries the repositories to find out which packages have new versions available.

Step 2: Download and install the updates.

user@debian:~$ sudo apt upgrade
âš  Note: If you run sudo apt upgrade before sudo apt update, the system will not find anything new to install, because the package list will be outdated. Always run the update first.
💡 Tip: You can combine both commands into a single line: sudo apt update && sudo apt upgrade

1.2 Install software

To install a program available in the official Debian repositories:

user@debian:~$ sudo apt install [package_name]

For example, to install Python:

user@debian:~$ sudo apt install python3
âš  Note: Packages installed with apt come from the official Debian repositories. They are safe and verified, but they may not always have the latest version of certain software.

1.3 Uninstall software

To remove a program you no longer need:

user@debian:~$ sudo apt remove [package_name]

If you also want to remove the configuration files left by the program:

user@debian:~$ sudo apt purge [package_name]

1.4 Clean up unnecessary packages

Over time, the system accumulates packages that are no longer needed. To free up space:

user@debian:~$ sudo apt autoremove
💡 Tip: It is a good practice to run sudo apt autoremove after uninstalling programs to keep the system clean.

1.5 Search for packages

If you don't remember the exact name of a package, you can search for it:

user@debian:~$ apt search [search_term]

Example:

user@debian:~$ apt search video editor

2. File System Navigation

In Linux, everything is a file, and the file system is organized in a directory structure that starts from the root, represented by /. Knowing how to navigate this structure is fundamental.

2.1 Where am I? — pwd

The pwd (Print Working Directory) command shows the full path of the directory you are currently in:

user@debian:~$ pwd
/home/user/Documents

2.2 View folder contents — ls

The ls command lists the files and folders in the current directory:

user@debian:~$ ls

With more useful options:

user@debian:~$ ls -la

2.3 Move between folders — cd

The cd (Change Directory) command allows you to navigate between directories:

user@debian:~$ cd [directory_path]

Practical examples:

Command Description
cd Documents Enters the Documents folder (within the current directory)
cd /home/user Goes directly to that absolute path
cd .. Moves up one level (to the parent directory)
cd ~ Goes to the current user's home directory
cd - Returns to the previous directory you were in

2.4 Create folders — mkdir

To create a new folder:

user@debian:~$ mkdir [folder_name]

To create multiple nested folders at once:

user@debian:~$ mkdir -p projects/web/css

2.5 Create files — touch

The touch command creates an empty file or updates the modification date of an existing one:

user@debian:~$ touch file.txt

2.6 Copy, move, and delete

These three commands are essential for handling files and folders:

Command Description
cp file.txt copy.txt Copies a file
cp -r folder/ new_folder/ Copies an entire folder (-r = recursive)
mv file.txt /another/path/ Moves a file to another location
mv old.txt new.txt Renames a file
rm file.txt Deletes a file
rm -r folder/ Deletes a folder and all its contents
âš  Note: The rm command does not send files to the trash: it deletes them permanently. Use it with caution, especially with the -r option.

3. View File Contents

Many times you will need to read the contents of text files directly from the terminal, without opening a graphical editor.

3.1 View all contents — cat

The cat command displays the entire contents of a file:

user@debian:~$ cat file.txt
💡 Tip: cat is ideal for short files. For long files, it is better to use less.

3.2 Read long files — less

The less command allows you to comfortably read long files by paginating the content:

user@debian:~$ less file.txt

Inside less, you can use the arrow keys to scroll, the spacebar to move forward one page, and the q key to exit.

3.3 View the first or last lines — head and tail

user@debian:~$ head -n 20 file.txt # Shows the first 20 lines
user@debian:~$ tail -n 20 file.txt # Shows the last 20 lines
💡 Tip: tail -f file.log is very useful for monitoring a log file in real-time as it is continuously written to.

4. Permissions and Users

Linux is a multi-user system with a robust permissions system. Understanding the basics will help you avoid errors and keep your system secure.

4.1 Who am I? — whoami

To find out which user you are currently working as:

user@debian:~$ whoami

4.2 Run as administrator — sudo

sudo (Super User DO) allows you to execute commands with administrator privileges without having to log in as root. Most system administration commands require it:

user@debian:~$ sudo [command]
âš  Note: Use it responsibly. A command executed with sudo has the power to modify any part of the system, including critical files.

4.3 Change file permissions — chmod

Every file in Linux has read (r), write (w), and execute (x) permissions for the owner, the group, and other users. The chmod command modifies these permissions:

user@debian:~$ chmod +x script.sh # Grant execute permission
user@debian:~$ chmod 755 script.sh # Numeric format: owner=7, group=5, others=5

5. Process Management

Sometimes a program freezes or consumes too many resources. The terminal gives you tools to monitor and control running processes.

5.1 View running processes — top and htop

The top command shows active processes and their CPU and memory usage in real-time:

user@debian:~$ top
💡 Tip: htop is a more visual and interactive version of top. If it is not installed, you can install it with: sudo apt install htop

5.2 List processes — ps

To see a list of the system's active processes:

user@debian:~$ ps aux

5.3 Terminate a process — kill

If you need to close an unresponsive process, first find its identifier (PID) using ps aux or top, and then use kill:

user@debian:~$ kill [PID]

If the process does not respond to kill, you can force it to close:

user@debian:~$ kill -9 [PID]

6. Basic Network Commands

These commands will help you diagnose connection problems and obtain information about your network.

Command Description
ping google.com Checks for connection with a server
ip a Shows network interfaces and their IP addresses
curl https://example.com Downloads the content of a URL
wget https://file.zip Downloads a file from the internet
ssh user@ip Connects to another machine via SSH