All cheatsheets
devops · Intermediate

Linux Terminal: Vital Commands

Lose the fear of the black screen. Navigate folders, manage files and control the server without touching the mouse. Survival basics.

6 sections · 30 snippets

File Management

Fundamental commands for navigating and manipulating files and directories on Linux.

List Detailed Files

Lists all files including hidden ones with permission, size, and date details

BASH
ls -lah

When to use: When you need to view all files with detailed information, including hidden files (starting with .)

Copy Files Recursively

Copies directories and their content recursively, preserving attributes

BASH
cp -r /origem /destino

When to use: For backing up entire directories or duplicating folder structures

Move or Rename Files

Moves files/directories or renames if destination is in the same directory

BASH
mv arquivo.txt /novo/caminho/mv arquivo_antigo.txt arquivo_novo.txt

When to use: To organize files or rename them directly via the terminal

Find Files by Name

Locates files in the system recursively using glob patterns

BASH
find /caminho -name "*.log"find . -type f -name "config*"

When to use: When you need to locate specific files in large directory structures

Create nested directories

Creates multiple levels of directories at once

BASH
mkdir -p /projeto/src/components/ui

When to use: To quickly create complex folder structures without needing to create each level manually

Permissions and Ownership

File and directory access control using chmod, chown, and umask.

Change Permissions Numerically

Sets permissions using octal notation (rwx = 7, rw- = 6, r-x = 5)

BASH
chmod 755 script.shchmod 644 arquivo.txt

When to use: 755 for executables (rwxr-xr-x), 644 for data files (rw-r--r--)

Change Permissions Symbolically

Modifies permissions using symbolic notation (u=user, g=group, o=others)

BASH
chmod u+x script.shchmod go-w arquivo.txt

When to use: When you want to modify specific permissions without changing others

Change Owner Recursively

Changes the owner and group of files/directories recursively

BASH
chown -R usuario:grupo /var/www/html

When to use: To correct permissions after deployment or web server configuration

View Octal Permissions

Displays file permissions in numeric format

BASH
stat -c '%a %n' arquivo.txt

When to use: To quickly check the numeric value of current permissions

Process Management

Monitoring, controlling, and manipulating running processes on the system.

List User Processes

Displays all processes of the current user with CPU and memory details

BASH
ps aux | grep usuariops -ef | grep nginx

When to use: To identify PIDs of specific processes or diagnose resource usage

Monitor Processes in Real-time

Interactive interface with real-time process updates

BASH
tophtop

When to use: For continuous monitoring of CPU, memory, and identifying problematic processes

Kill Process by PID

Terminates process using different signal levels

BASH
kill 1234kill -9 1234kill -SIGTERM 1234

When to use: kill for graceful termination, kill -9 to force immediate termination

Kill Process by Name

Terminates all processes matching the name

BASH
pkill nginxkillall node

When to use: When you know the process name but not the PID

Run process in background

Starts process in the background, freeing up the terminal

BASH
npm run dev &nohup python3 script.py &

When to use: To run long scripts without blocking the terminal (nohup keeps it running after logout)

Network and Connectivity

Tools for network diagnostics, file transfer, and connectivity testing.

Test Connectivity

Sends ICMP packets to check if the host is reachable

BASH
ping -c 4 google.comping 192.168.1.1

When to use: To check network connectivity and latency (-c limits the number of packets)

Download Files

Downloads files from the web via HTTP/HTTPS

BASH
wget https://example.com/file.zipcurl -O https://example.com/file.tar.gz

When to use: wget for simple downloads, curl for APIs and more complex requests

View Ports in Use

Lists all open TCP/UDP ports and associated processes

BASH
netstat -tulpnss -tulpn

When to use: To identify port conflicts or check if a service is listening

Secure Transfer (SCP)

Copies files between machines via SSH

BASH
scp arquivo.txt user@servidor:/path/scp -r /pasta user@servidor:/destino

When to use: To securely transfer files between servers (use -r for directories)

Check External IP

Discovers the machine's public IP address

BASH
curl ifconfig.mewget -qO- ifconfig.me

When to use: To know your public IP when working remotely or configuring firewalls

Package Management

Installing, updating, and removing software using package managers (APT/YUM).

Update Package List (Debian/Ubuntu)

Synchronizes the list of available packages with repositories

BASH
sudo apt update

When to use: Always before installing new packages to ensure updated versions

Install Package (Debian/Ubuntu)

Downloads and installs package with all dependencies

BASH
sudo apt install nginx -y

When to use: To install software via official repositories (-y automatically confirms)

Update System (Debian/Ubuntu)

Updates all installed packages to newer versions

BASH
sudo apt update && sudo apt upgrade -y

When to use: Regular system maintenance for security patches and improvements

Remove Package (Debian/Ubuntu)

Uninstalls package, keeping configuration files

BASH
sudo apt remove pacotesudo apt purge pacote

When to use: remove keeps configs, purge removes everything (useful for clean reinstallation)

Search packages (Debian/Ubuntu)

Searches for available packages in repositories

BASH
apt search python3apt-cache search nodejs

When to use: To find the exact package name before installing

System Information

Commands for getting hardware, OS, and resource usage information.

Disk Usage

Displays used and available space on all mounted partitions

BASH
df -h

When to use: To check for sufficient disk space (-h displays in human-readable format)

Directory Size

Calculates total size of directories and files

BASH
du -sh /var/logdu -h --max-depth=1 /home

When to use: To identify which directories are consuming the most space

Memory Usage

Shows RAM and swap usage in human-readable format

BASH
free -h

When to use: To diagnose memory issues or check if swap is being used

CPU Information

Displays processor details (model, cores, frequency)

BASH
lscpucat /proc/cpuinfo

When to use: To check hardware specifications before optimizations

System uptime

Shows how long the system has been running and average load

BASH
uptime

When to use: To check server stability and load average

System version

Identifies Linux distribution and kernel version

BASH
uname -acat /etc/os-release

When to use: To document environment or check software compatibility