Linux is a Unix-like, open-source operating system kernel first released by Linus Torvalds in 1991. When combined with GNU utilities and other software, it forms complete operating systems (distributions) like Ubuntu, Debian, Fedora, and Arch Linux. Linux dominates the server market, powers most of the internet’s infrastructure, and is the foundation for Android and countless embedded systems.
Every running program is a process with a unique PID (Process ID). Processes have a parent-child relationship forming a tree structure, with PID 1 (init/systemd) at the root.
fork()
The fork system call clones the current process to create a new process. It creates a new process (the child process) by duplicating the state of the existing process with a few minor differences. The child process does not start from main. Instead it returns from fork() just as the parent process does.
After fork(), the parent receives the child’s PID while the child receives 0. This is how each process knows its role:
export VAR="value" # Set variable for current session and child processesecho $VAR # Access variableenv # List all environment variablesprintenv VAR # Print specific variableunset VAR # Remove variable
Important Environment Variables
Variable
Description
PATH
Directories to search for executables
HOME
User’s home directory
USER
Current username
SHELL
Current shell
PWD
Current working directory
EDITOR
Default text editor
LANG
System locale
PATH
The PATH variable contains colon-separated directories where the shell looks for executables:
echo $PATH# /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin# Add directory to PATHexport PATH="$HOME/bin:$PATH"
Useful Shell Features
!! # Repeat last command!$ # Last argument of previous commandCtrl+R # Reverse search historyCtrl+L # Clear screenCtrl+A / Ctrl+E # Start / end of lineCtrl+U / Ctrl+K # Delete to start / end of line
Networking Commands
Command
Description
ip addr
Show IP addresses
ip link
Show network interfaces
ip route
Show routing table
ss -tuln
Show listening TCP/UDP ports
ss -tp
Show TCP connections with process
netstat -tuln
Show listening ports (legacy)
curl -I url
Fetch HTTP headers
curl -X POST -d 'data' url
POST request
wget url
Download file
dig domain
DNS lookup
nslookup domain
DNS lookup (legacy)
host domain
DNS lookup (simple)
ping host
Test connectivity
traceroute host
Trace packet route
mtr host
Combined ping and traceroute
nc -zv host port
Test TCP port connectivity
Firewall (iptables/nftables)
Modern systems use nftables, but many still use iptables:
iptables -L # List rulesiptables -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SSHufw status # Ubuntu firewall statusufw allow 22 # Allow port 22
Service Management
Most modern Linux distributions use Systemd for service management:
systemctl status nginx # Check service statussystemctl start nginx # Start servicesystemctl stop nginx # Stop servicesystemctl restart nginx # Restart servicesystemctl enable nginx # Start on bootsystemctl disable nginx # Don't start on bootsystemctl daemon-reload # Reload unit files after changesjournalctl -u nginx # View service logsjournalctl -fu nginx # Follow service logs
Useful Developer Tools
Tool
Description
htop
Interactive process viewer
tmux / screen
Terminal multiplexers
ripgrep (rg)
Fast recursive grep
fd
Fast, user-friendly find
fzf
Fuzzy finder
bat
Cat with syntax highlighting
jq
JSON processor
yq
YAML processor
ncdu
Disk usage analyser
tree
Directory tree visualisation
watch
Run command repeatedly
strace
Trace system calls
lsof
List open files
lsof -i :8080
Find process using port
Common Tasks
Disk Usage
df -h # Filesystem disk spacedu -sh * # Size of items in current directorydu -sh */ | sort -h # Sorted directory sizesncdu # Interactive disk usage
Logs
journalctl -xe # Recent systemd logs with contextdmesg # Kernel ring buffertail -f /var/log/syslog # Follow syslog