Linux
02 / 03

Processes, Networking & System

Processes, Networking & System

Process Management

# View processes
ps aux                       # all processes (BSD format)
ps -ef                       # all processes (UNIX format)
ps aux | grep nginx          # find process by name
top                          # live view (press q to quit)
htop                         # better top (install separately)
pgrep nginx                  # find PID by name
pidof nginx                  # PID of running program

# Kill processes
kill PID                     # send SIGTERM (graceful stop)
kill -9 PID                  # send SIGKILL (force kill)
killall nginx                # kill all processes by name
pkill -f "python app.py"    # kill by pattern

# Background / foreground
command &                    # run in background
jobs                         # list background jobs
fg %1                        # bring job 1 to foreground
bg %1                        # send job to background
nohup command &              # run immune to hangup (terminal close)
disown %1                    # detach from shell

# nice / renice — CPU priority
nice -n 10 command           # run with lower priority (nice value 10)
renice -n 5 -p PID           # change priority of running process

# Signals
SIGTERM (15) — graceful termination
SIGKILL (9)  — force kill (cannot be caught)
SIGHUP (1)   — reload config (nginx, sshd)
SIGUSR1/2    — user-defined

Networking

# IP / interfaces
ip addr show                 # show IP addresses
ip link show                 # show interfaces
ifconfig                     # older alternative
hostname -I                  # show all IP addresses

# Connectivity
ping google.com              # test connectivity
ping -c 4 google.com        # only 4 packets
traceroute google.com        # trace route
mtr google.com               # continuous traceroute

# DNS
nslookup domain.com          # DNS lookup
dig domain.com               # detailed DNS
dig domain.com +short        # just the IPs
dig @8.8.8.8 domain.com     # use specific DNS server

# Ports and connections
ss -tlnp                     # listening TCP ports + processes
ss -anp                      # all connections
netstat -tlnp                # older alternative
lsof -i :8080                # what's on port 8080
lsof -i tcp                  # all TCP connections

# HTTP requests
curl https://api.example.com
curl -X POST -H "Content-Type: application/json" -d '{"key":"val"}' https://api.example.com
curl -u user:pass https://api.example.com
curl -o output.txt https://file.example.com
curl -I https://example.com  # headers only
wget https://file.example.com/file.tar.gz

# Transfer files
scp user@host:/remote/file ./local/     # copy from remote
scp ./local/file user@host:/remote/     # copy to remote
rsync -avz ./src/ user@host:/dst/       # sync directories
rsync -avz --exclude node_modules ./    # exclude

System Administration

# systemd — service management
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx         # reload config without stopping
systemctl enable nginx         # start on boot
systemctl disable nginx
systemctl list-units --type=service

journalctl -u nginx            # logs for service
journalctl -u nginx -f         # follow logs
journalctl --since "1 hour ago"
journalctl -n 100              # last 100 lines

# Users and groups
useradd -m -s /bin/bash username    # create user with home + shell
userdel -r username                 # delete user + home
passwd username                     # set password
usermod -aG docker username         # add user to group
groups username                     # show user's groups
id username                         # user/group IDs
who                                 # who is logged in
last                                # login history

# Cron
crontab -e                     # edit user crontab
crontab -l                     # list crontab
# Format: min hour day month weekday command
# 0 2 * * * /scripts/backup.sh      (2am daily)
# */15 * * * * /scripts/check.sh    (every 15 minutes)
# 0 9 * * 1-5 /scripts/report.sh   (9am weekdays)

# Environment
env                            # all environment variables
export VAR=value               # set env var
echo $PATH
source ~/.bashrc               # reload shell config
which node                     # path to executable
whereis bash                   # find binary + man pages

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free