Essential Linux Commands and System Administration Techniques
Boot Scripts
/etc/rc.local → rc.d/rc.local (custom boot initialization)
All boot scripts reside in /etc/rc.d/, e.g., /etc/rc.d/init.d/network for network startup.
Ensure execution permissions: chmod +x /etc/rc.d/rc.local
Date and Timestamp Operations
Current date: date
Unix timestamp: date +%s
Convert timestamp: date -d @1654263019
Date to timestamp: date -d '2021-03-01 17:49:23' +%s
File Verification
MD5 checksum: md5sum filename
Conditional execution: command1 && command2 (executes command2 only if command1 succeeds)
Decompress .gz: gunzip file.gz
Disk Usage
Directory size: du -h --max-depth=1 /path
Summary size: du -sh ./*
Process memory:
while true; do
clear;
date;
ps aux | grep process | grep -v grep | awk '{print $6/1024 "M" "\t" $0}';
sleep 1;
done
Environment Variables
List variables: export -p
Set variable: export VAR=value
System Navigation
Home directory: echo ~
Change hostname: hostname -b newname
Network Operations
Public IP: curl ipinfo.io
GET request:
curl -v -X GET 'http://192.168.16:8080/v1/endpoint?param1=value1\¶m2=value2'
POST request:
curl -H "Content-Type: application/json" -X POST -d '{"key":"value"}' "http://host:port/endpoint"
Process Management
Graceful termination: kill -15 PID
Version Control
Git reset to commit:
git reset --hard COMMIT_HASH
git push origin master --force
Terminal Multiplexing
Start session: screen -S session_name
List sessions: screen -ls
Reattach: screen -r session_id
Detach: Ctrl+A, D
File Operations
Append content:
cat >> file.txt <<EOF
content
EOF
Multi-line append: echo -e "line1\nline2" >> file.txt
SSH Configuraton
Generate keys: ssh-keygen -t rsa -P ''
Copy key: ssh-copy-id user@host
Network Analysis
Open ports: netstat -anp
Text search: grep -r "pattern" ./
Text Editing
Search/replace in vi: :n,$s/old/new/g
Convert line endings: :set ff=unix
User Management
List users: compgen -u or cat /etc/passwd
Add user:
useradd -m username
passwd username
Batch user creation:
ansible group -m shell -a "newusers /path/user_list.txt"
Privilege Escalation
Edit sudoers: visudo
Root shell: sudo -s
File Search
Locate file: find / -name "filename"
Background Processes
Daemonize: nohup command >> logfile 2>&1 &
Package Management
Clear cache: yum clean all
Find package: yum provides command
Install: yum install package
List installed: yum list installed
File Transfer
Secure copy: scp file user@host:/path
Text Processing
Line substitution: sed -i '134 s/old/new/g' file
Prepend text: sed -i 's/^/prefix/g' file
Insert lines: sed -e '4a\newline1\nnewline2' file
Process Inspection
Thread view: ps -T -p PID
System Monitoring
Resource usage: top, htop
Service status: systemctl status service
Network Configuration
Interface info: ifconfig
Routing table: route -n
Kernel Modules
List modules: lsmod
Load module: modprobe module_name
Storage Management
Disk info: fdisk -l
Filesystems: df -hT
Partitioning: fdisk /dev/device
Format: mkfs.ext4 /dev/partition
Mount: mount /dev/partition /path
Auto-mount: echo '/dev/partition /path ext4 defaults 0 0' >> /etc/fstab
System Information
CPU: cat /proc/cpuinfo
Memory: cat /proc/meminfo
OS version: cat /etc/redhat-release
Compilation
Development tools: yum groupinstall "Development tools"
Common dependencies:
yum install curl-devel zlib-devel openssl-devel ncurses-devel libxml2-devel