Linux / Shell
Linux administration และ shell scripting — process management, networking, monitoring
What I Can Do
- จัดการ Linux servers สำหรับ production workloads
- เขียน shell scripts สำหรับ automation, deployment, monitoring
- Debug performance issues — CPU, memory, disk, network
- ตั้งค่า firewall, SSH, user permissions
- จัดการ services ด้วย systemd
Commands I Use Daily
# ดูไฟล์ทั้งหมดพร้อม permissions
ls -la
# ดู processes ทั้งหมด
ps aux
# monitor system แบบ real-time
top # built-in
htop # interactive, สวยกว่า
# ค้นหาข้อความในไฟล์
grep -r "pattern" /path
# ค้นหาไฟล์
find / -name "*.log" -mtime -7
# ดู log แบบ real-time
tail -f /var/log/syslog
# เปลี่ยน permissions / ownership
chmod 755 script.sh
chown user:group file
# ดู disk usage
df -h
# SSH เข้า server
ssh user@server
# จัดการ services
systemctl status nginx
systemctl restart nginxFile System Hierarchy
Linux file system เริ่มจาก / (root) — /home user data, /etc config files, /var variable data (logs, cache), /usr user programs, /tmp temporary files, /proc process info (virtual), /dev devices
Basic Commands
คำสั่งพื้นฐานที่ใช้ทุกวัน — ls (list), cd (change dir), cp (copy), mv (move/rename), rm (remove), mkdir (create dir), cat (read file), less/more (paginate), touch (create empty file)
File Permissions
ทุกไฟล์มี owner, group, others permissions — rwx (read/write/execute) แสดงเป็น octal เช่น 755 = owner rwx, group rx, others rx, chmod เปลี่ยน permissions, chown เปลี่ยน ownership
Pipes & Redirects
- Pipe (
|) — ส่ง output ของ command หนึ่งเป็น input ของอีก command เช่นcat file | grep pattern | sort - Redirect —
>write to file (overwrite),>>append,<read from file,2>redirect stderr tee— write ทั้ง stdout และ file พร้อมกัน
Environment Variables & PATH
export VAR=value— set environment variable สำหรับ current session และ child processes$PATH— list ของ directories ที่ shell ค้นหา executables, คั่นด้วย:.bashrc/.zshrc— load ทุกครั้งที่เปิด shell,.profile/.bash_profile— login shell
Package Management
- Debian/Ubuntu —
apt update,apt install,apt remove,dpkg - RHEL/CentOS —
yum/dnf install,rpm - Alpine —
apk add,apk del(ใช้บ่อยใน Docker containers) - Lock versions ใน production เพื่อ reproducibility
Text Processing (grep/sed/awk)
- grep — ค้นหา pattern ในไฟล์,
-rrecursive,-icase-insensitive,-Eregex - sed — stream editor,
sed 's/old/new/g'find-replace,-iedit in-place - awk — pattern scanning,
awk '{print $1, $3}'print specific columns, powerful สำหรับ structured text
Process Management
ps aux— list processes,top/htop— real-time monitoringkill PID— send signal (default SIGTERM),kill -9 PID— force kill (SIGKILL)nohup command &— run ใน background, survive terminal closejobs,fg,bg— manage background jobs
Shell Scripting Basics
#!/bin/bashVariables, conditionals (if/elif/else/fi), loops (for/while/until), functions, exit codes ($?), command substitution ($(command)), string operations ใช้ automate repetitive tasks
Cron Jobs
Schedule commands ให้ run ตามเวลา — crontab -e edit, format: minute hour day month weekday command เช่น 0 2 * * * /scripts/backup.sh run ทุกวัน ตี 2, crontab -l ดูรายการ
Systemd & Service Management
systemctl start/stop/restart/status service— จัดการ servicessystemctl enable/disable service— auto-start on bootjournalctl -u service -f— ดู logs ของ service แบบ real-time- สร้าง custom service ด้วย
.servicefile ใน/etc/systemd/system/
SSH & Key Authentication
ssh-keygen -t ed25519— สร้าง key pairssh-copy-id user@server— copy public key ไป server~/.ssh/config— ตั้ง aliases, proxy jumps, port forwarding- Key-based auth ปลอดภัยกว่า password, disable password auth ใน production
Networking Commands
curl/wget— HTTP requests / download filesnetstat -tlnp/ss -tlnp— ดู listening portsping,traceroute,dig/nslookup— network diagnosticsip addr/ifconfig— ดู network interfacesnc(netcat) — TCP/UDP connections, port scanning
Disk Management
df -h— disk space usage per filesystemdu -sh *— directory sizeslsblk— list block devicesmount/umount— mount filesystemsfdisk/parted— partition management
User & Group Management
useradd/userdel/usermod— manage usersgroupadd/groupmod— manage groups/etc/passwd,/etc/shadow,/etc/group— user/group databasessudo— execute as another user,/etc/sudoersconfig ด้วยvisudo
Performance Monitoring
top/htop— CPU, memory per processvmstat— virtual memory, CPU, I/O statsiostat— disk I/O statisticsfree -h— memory usagesar— historical system activity,dstat— versatile resource stats
Log Management
/var/log/— standard log directory (syslog,auth.log,kern.log)journalctl— systemd journal, filter by unit, time, prioritylogrotate— automatic log rotation, compression, retention- Centralized logging ด้วย rsyslog, Fluentd, หรือ ELK stack
Firewall (iptables/ufw)
- iptables — low-level packet filtering, chains (INPUT/OUTPUT/FORWARD), rules
- ufw (Uncomplicated Firewall) — simplified frontend สำหรับ iptables
ufw allow 22/tcp,ufw enable,ufw status— basic firewall setup- Default deny incoming, allow outgoing เป็น best practice
Containerization Primitives (cgroups/namespaces)
- Namespaces — isolate resources (PID, network, mount, user) — แต่ละ container เห็น environment ของตัวเอง
- cgroups — limit และ account resource usage (CPU, memory, I/O) ต่อ process group
- Docker/containerd ใช้ทั้งสองอย่างนี้เป็นพื้นฐาน
Kernel Tuning (sysctl)
/etc/sysctl.conf หรือ sysctl -w ปรับ kernel parameters — เช่น net.core.somaxconn (max connections), vm.swappiness (swap behavior), fs.file-max (max open files) ใช้ tune สำหรับ high-performance servers