Tech & DevOps HubEspace Tech & DevOps

Explorez le monde du Dev, du Cloud et des outils DevOps à travers nos articles et discussions Explore the world of development, the cloud and DevOps tools
 FR      EN
Linux
Compression
Compress a folder
tar -czf archive.tar.gz myfolder/

Creates a gzip-compressed archive
Windows equivalent: Compress-Archive -Path myfolder -DestinationPath archive.zip
Unzip an archive
tar -xzf archive.tar.gz

Extract the contents of a gzip archive.
Équivalent PowerShell (Windows): Compress-Archive -Path my_folder -DestinationPath archive.zip
Note: tar is also available natively on recent versions of Windows
Filesystem
Display nth CSV field
cut -d',' -f3 users.csv

This command extracts the third column from the “users.csv” file using a comma as the delimiter
For complex CSV files, use dedicated tools such as csvkit or awk
Show first 10 lines
head -n 10 logfile.txt

Displays first 10 lines of file.
Windows equivalent: Get-Content logfile.txt -TotalCount 10
Count lines
wc -l logfile.txt

Counts number of lines in file.
Windows equivalent: (Get-Content logfile.txt).Count
output: 152 logfile.txt
Extract column
cut -d":" -f1 /etc/passwd

Extracts specific field from CSV.
Windows équivalent: Get-Content file.txt | ForEach-Object { $_.Split(":")[0] }
Recursive search with numbers
grep -rn "motif" .

Searches recursively with line numbers.
Recursive replacement
grep -rl 'motif' ./ | xargs sed -i 's/motif/nouveau/g'

Replaces string in all matching files.
Top 10 largest files
du -ah . | sort -rh | head -n 10 

Lists biggest files/directories.
Top 5 frequent lines
sort file.txt | uniq -c | sort -nr | head -n 5 

Shows most common lines in file.
View command history
history

Displays shell history.
Windows equivalent: Get-History
Logs
View kernel logs
dmesg | tail -n 20

Displays last kernel messages.
List modified files (24h)
find . -type f -mtime -1

Shows files modified in last 24 hours.
View service logs
journalctl -u nginx -n 50

Shows last 50 systemd log entries.
Network
Show network interfaces
ip addr show

Displays interfaces and IPs.
DNS lookup
dig example.com

Displays DNS records.
Test network connectivity
ping -c 3 example.com

Sends ICMP ping packets.
Test port connectivity
nc -zv host 443 

Tests if remote port is reachable.
List open ports
ss -tuln 

Shows open TCP/UDP ports.
Process
Kill process by PID
kill -9 1234

Force the process with PID 1234 to stop
To get the PID (example for nginx): ps aux | grep nginx | grep -v grep to exclude the grep process from the results.
Or, use a modern command with a regular expression: ps aux | grep [n]ginx
Windows equivalent: Stop-Process -Id 1234 -Force
Run SSH command loop
for host in server1 server2 server3; do ssh $host "uptime"; done

Runs command on multiple servers via SSH.
Run command in background
sleep 60 &

Launch a process in the background.
Windows equivalent: Start-Job { Start-Sleep 60 }
List active processes
ps aux

Shows processes with CPU/memory usage.
Windows equivalent: Get-Process
Monitor process
top -p <PID> 

Monitors live resource usage of a PID.
Scheduling
Run a delayed task
at now + 5 minutes -f script.sh

Run a script after a delay.
Linux only
Windows equivalent: Start-Sleep 300 ; .\script.ps1
Schedule a recurring task
crontab -e

Edit the cron table to add scheduled tasks.
Linux only
Windows equivalent: Task Scheduler (GUI) or schtasks
Service
Enable service at boot
systemctl enable serviceName

Enables auto-start on boot.
Stop - Start - Restart a service
systemctl start serviceName

e.g: Start a systemd service
Related commands to manage the service
Stop : sudo systemctl stop serviceName
Restart (after configuration changes) : sudo systemctl restart serviceName
Enable at boot : sudo systemctl enable serviceName
Windows equivalent: Start-Service serviceName
Check service status
systemctl status serviceName

Allows you to check the service's status in real time. It provides detailed status information, the last error, and the PID. Linux only
Check:
Active: active (running) : the service is running
Loaded: ...; enabled; : will start automatically on boot

Windows equivalent: Get-Service serviceName
System
Follow last 5 lines
tail -f -n 5 fichier.log

Shows last 5 lines and updates in real time.
Tail with line numbers
tail -f -n +1 app.log | nl 

Shows log lines with numbering.
Follow logs in real time
journalctl -f

Continuously displays newly added lines. It queries the centralised logging daemon directly.
It displays logs from the kernel, the system, and all services (such as Docker, Jenkins, SSH, etc.) in a unified view.
To view real-time monitoring, add the -f
option. Example: monitor a specific service (e.g. Docker): journalctl -u docker -f
Monitor only system errors and alerts: journalctl -p err -f
Monitor kernel logs: journalctl -k -f
Windows equivalent: Get-Content -Path C:\path\to\log -Wait -Tail 50
Top CPU consumers
ps -eo pid,comm,%cpu --sort=-%cpu | head -n 10

Lists top CPU-consuming processes.
Check folder disk usage
du -sh *

Displays size of files and directories.
Check disk space
df -h

Shows disk usage per filesystem.
Check real-time CPU/memory
top

Shows active processes and resource usage.
Check memory usage
free -h

Displays total, used and available memory.