Skip to main content

System Operations

Process Management

Viewing Processes

# List all processes
ps aux # All processes with detailed info
ps -ef # All processes with full format
ps -u username # Processes for specific user

# Process tree
pstree # Show process hierarchy
pstree -p # Include PIDs
pstree username # Tree for specific user

# Top processes
top # Interactive process viewer
htop # Enhanced top (if installed)
top -u username # Top for specific user
top -p 1234 # Top for specific PID

# Find processes
pgrep process_name # Find PID by name
pgrep -f pattern # Find by full command line
pidof process_name # Get PID of running process

Controlling Processes

# Kill processes
kill PID # Terminate process
kill -9 PID # Force kill
kill -TERM PID # Graceful termination
kill -HUP PID # Hangup signal (often reload config)

# Kill by name
killall process_name # Kill all instances
pkill process_name # Kill by name pattern
pkill -f pattern # Kill by full command line

# Background and foreground
command & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Send job 1 to background
disown %1 # Detach job from shell

# Suspend and resume
Ctrl+Z # Suspend current process
fg # Resume suspended process
bg # Resume in background

Process Information

# Detailed process info
ps -p PID -o pid,ppid,cmd,vsz,rss,time
lsof -p PID # Files opened by process
strace -p PID # System calls made by process
/proc/PID/ # Process information directory

# Process resource usage
time command # Time command execution
/usr/bin/time -v command # Verbose timing info

System Information

System Status

# System uptime and load
uptime # System uptime and load average
w # Who is logged in and what they're doing
who # Currently logged in users
last # Login history
lastlog # Last login for all users

# System information
uname -a # All system information
uname -s # Kernel name
uname -r # Kernel release
uname -m # Machine architecture
hostname # System hostname
hostname -I # IP addresses

Hardware Information

# CPU information
lscpu # CPU architecture info
cat /proc/cpuinfo # Detailed CPU info
nproc # Number of processing units

# Memory information
free -h # Memory usage (human readable)
free -m # Memory usage in MB
cat /proc/meminfo # Detailed memory info
vmstat # Virtual memory statistics
vmstat 1 5 # Update every 1 second, 5 times

# Disk information
df -h # Disk space usage
df -i # Inode usage
du -h directory # Directory size
du -sh * # Size of all items in current directory
lsblk # List block devices
fdisk -l # List disk partitions (root required)

System Resources

# I/O statistics
iostat # CPU and I/O statistics
iostat -x 1 # Extended I/O stats every second
iotop # I/O usage by process

# Network statistics
netstat -tuln # Network connections
netstat -i # Network interface statistics
ss -tuln # Socket statistics (modern netstat)
ss -s # Summary statistics

# System calls and performance
strace command # Trace system calls
ltrace command # Trace library calls
perf top # Performance monitoring

File System Operations

Disk Usage

# Disk space
df -h # Human-readable disk usage
df -T # Show filesystem type
df /path # Usage for specific mount point

# Directory size
du -h directory # Human-readable directory size
du -sh directory # Summary only
du -h --max-depth=1 # One level deep
du -h | sort -hr # Sorted by size
ncdu # Interactive disk usage analyzer

# Find large files
find /path -type f -size +100M # Files larger than 100MB
find /path -type f -exec ls -lh {} \; | sort -k5 -hr

Mount Operations

# View mounted filesystems
mount # Show all mounted filesystems
mount | column -t # Formatted output
findmnt # Tree view of mounted filesystems
cat /proc/mounts # Kernel view of mounts

# Mount filesystem
mount /dev/sdb1 /mnt/usb # Mount USB drive
mount -o ro /dev/sdb1 /mnt # Mount read-only
mount -t ext4 /dev/sdb1 /mnt # Specify filesystem type

# Unmount filesystem
umount /mnt/usb # Unmount by mount point
umount /dev/sdb1 # Unmount by device
umount -l /mnt/usb # Lazy unmount
fuser -km /mnt/usb # Kill processes using mountpoint

File System Checking

# Check filesystem
fsck /dev/sdb1 # Check filesystem
fsck -y /dev/sdb1 # Automatically fix errors
e2fsck /dev/sdb1 # Check ext2/3/4 filesystem

# Bad blocks
badblocks -v /dev/sdb1 # Check for bad blocks
badblocks -w /dev/sdb1 # Write test (destructive)

Network Operations

Network Configuration

# Interface information
ip addr show # Show IP addresses
ip link show # Show network interfaces
ifconfig # Network interface configuration
iwconfig # Wireless interface configuration

# Routing
ip route show # Show routing table
route -n # Numeric routing table
ip route add default via 192.168.1.1 # Add default route
ip route del 192.168.1.0/24 # Delete route

# DNS
nslookup example.com # DNS lookup
dig example.com # DNS lookup with more detail
host example.com # Simple DNS lookup
systemd-resolve --status # DNS configuration (systemd)

Network Testing

# Connectivity testing
ping -c 4 example.com # Ping 4 times
ping6 -c 4 example.com # IPv6 ping
traceroute example.com # Trace route to destination
mtr example.com # Combined ping and traceroute

# Port testing
telnet example.com 80 # Test TCP connection
nc -zv example.com 80 # Test port with netcat
nmap -p 22,80,443 example.com # Port scan

# Network monitoring
netstat -tuln # Network connections
ss -tuln # Socket statistics
lsof -i # Files opened by network processes
lsof -i :80 # Processes using port 80

Network Transfer

# Download files
wget https://example.com/file.tar.gz
wget -c https://example.com/file.tar.gz # Continue download
curl -O https://example.com/file.tar.gz
curl -L https://example.com/file.tar.gz # Follow redirects

# Upload files
scp file.txt user@server:/path/
rsync -avz local_dir/ user@server:/remote_dir/

Service Management

Systemd Services

# Service status
systemctl status service_name
systemctl is-active service_name
systemctl is-enabled service_name

# Service control
systemctl start service_name
systemctl stop service_name
systemctl restart service_name
systemctl reload service_name

# Service configuration
systemctl enable service_name # Enable at boot
systemctl disable service_name # Disable at boot
systemctl mask service_name # Prevent service from starting
systemctl unmask service_name # Allow service to start

# List services
systemctl list-units --type=service
systemctl list-units --type=service --state=active
systemctl list-units --type=service --state=failed

Service Logs

# View logs
journalctl -u service_name # Logs for specific service
journalctl -u service_name -f # Follow logs
journalctl -u service_name --since="2023-01-01"
journalctl -u service_name --until="2023-01-02"

# System logs
journalctl -b # Boot logs
journalctl -k # Kernel logs
journalctl --disk-usage # Log disk usage

User and Group Management

User Information

# Current user info
whoami # Current username
id # User and group IDs
groups # Groups for current user
groups username # Groups for specific user

# User details
finger username # User information
getent passwd username # User from passwd database
last username # Login history for user

User Management (requires root)

# Add user
useradd username
useradd -m -s /bin/bash username # Create home directory and set shell
adduser username # Interactive user creation (Debian/Ubuntu)

# Modify user
usermod -aG group username # Add user to group
usermod -s /bin/zsh username # Change shell
usermod -l newname oldname # Rename user

# Delete user
userdel username # Delete user
userdel -r username # Delete user and home directory

# Password management
passwd username # Change password
passwd -l username # Lock account
passwd -u username # Unlock account
chage -l username # Password aging info

Group Management (requires root)

# Group operations
groupadd groupname # Create group
groupdel groupname # Delete group
groupmod -n newname oldname # Rename group

# Group membership
gpasswd -a username groupname # Add user to group
gpasswd -d username groupname # Remove user from group

System Monitoring

Real-time Monitoring

# System load
uptime # Load average
tload # Load average graph
w # System load and user activity

# Resource usage
top # Process monitor
htop # Enhanced process monitor
iotop # I/O monitor
nethogs # Network monitor per process

System Logs

# Log files
tail -f /var/log/syslog # System log
tail -f /var/log/auth.log # Authentication log
tail -f /var/log/kern.log # Kernel log
tail -f /var/log/daemon.log # Daemon log

# Log analysis
grep "error" /var/log/syslog
grep "failed" /var/log/auth.log
zgrep "pattern" /var/log/old.log.gz # Search compressed logs

Performance Monitoring

System Performance

# CPU usage
mpstat # CPU statistics
mpstat 1 5 # Update every 1 second, 5 times
sar -u 1 5 # CPU utilization

# Memory usage
vmstat 1 5 # Virtual memory statistics
free -h # Memory usage
pmap PID # Memory map of process

# I/O performance
iostat -x 1 # Extended I/O statistics
iotop # I/O usage by process

Process Monitoring

# Process statistics
ps aux --sort=-%cpu # Sort by CPU usage
ps aux --sort=-%mem # Sort by memory usage
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu

# Process resource usage
pidstat 1 5 # Process statistics
pidstat -r 1 5 # Memory usage
pidstat -d 1 5 # I/O usage

Environment Variables

System Environment

# Environment variables
env # All environment variables
printenv # All environment variables
printenv PATH # Specific variable
echo $PATH # Variable value

# Set environment variables
export VAR=value # Export variable
VAR=value command # Set for single command
unset VAR # Remove variable

# Common environment variables
echo $HOME # Home directory
echo $USER # Current user
echo $SHELL # Current shell
echo $PATH # Executable search path
echo $PWD # Current directory
echo $OLDPWD # Previous directory

Shell Configuration

# Shell configuration files
~/.bashrc # Bash configuration
~/.bash_profile # Bash login configuration
~/.profile # Shell-independent profile
/etc/profile # System-wide profile
/etc/bash.bashrc # System-wide bash configuration

# Reload configuration
source ~/.bashrc # Reload bash configuration
. ~/.bashrc # Alternative syntax

Security Operations

File Security

# File permissions
ls -l file # View permissions
chmod 755 file # Change permissions
chown user:group file # Change ownership
chgrp group file # Change group

# Special permissions
chmod +t directory # Sticky bit
chmod +s file # Setuid/setgid
ls -la /tmp # View sticky bit
find /usr -perm -4000 # Find setuid files

System Security

# Login monitoring
who # Current users
w # Current users with activity
last # Login history
lastlog # Last login per user
lastb # Failed login attempts

# Process security
ps aux | grep suspicious
lsof -i # Network connections
netstat -tuln # Network listeners

Best Practices

System Maintenance

# Regular maintenance tasks
# Update package lists
apt update && apt upgrade # Debian/Ubuntu
yum update # CentOS/RHEL

# Clean up
apt autoremove # Remove unused packages
apt autoclean # Clean package cache
yum clean all # Clean YUM cache

# Log rotation
logrotate -f /etc/logrotate.conf

Performance Optimization

# Monitor system regularly
uptime # Check load
free -h # Check memory
df -h # Check disk space
iostat # Check I/O

# Identify bottlenecks
top -o %CPU # High CPU processes
top -o %MEM # High memory processes
iotop # I/O intensive processes

Security Best Practices

# Regular security checks
ps aux | grep -v "^\[.*\]$" | grep -v "root" # Unusual processes
netstat -tuln | grep LISTEN # Network listeners
find /tmp -type f -atime +7 -delete # Clean old temp files