Skip to content
← All Skills
🐧

Linux / Shell

InfrastructureOfficial Site ›

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

bash
# ดูไฟล์ทั้งหมดพร้อม 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 nginx

File 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/Ubuntuapt update, apt install, apt remove, dpkg
  • RHEL/CentOSyum/dnf install, rpm
  • Alpineapk add, apk del (ใช้บ่อยใน Docker containers)
  • Lock versions ใน production เพื่อ reproducibility

Text Processing (grep/sed/awk)

  • grep — ค้นหา pattern ในไฟล์, -r recursive, -i case-insensitive, -E regex
  • sed — stream editor, sed 's/old/new/g' find-replace, -i edit 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 monitoring
  • kill PID — send signal (default SIGTERM), kill -9 PID — force kill (SIGKILL)
  • nohup command & — run ใน background, survive terminal close
  • jobs, fg, bg — manage background jobs

Shell Scripting Basics

bash
#!/bin/bash

Variables, 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 — จัดการ services
  • systemctl enable/disable service — auto-start on boot
  • journalctl -u service -f — ดู logs ของ service แบบ real-time
  • สร้าง custom service ด้วย .service file ใน /etc/systemd/system/

SSH & Key Authentication

  • ssh-keygen -t ed25519 — สร้าง key pair
  • ssh-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 files
  • netstat -tlnp / ss -tlnp — ดู listening ports
  • ping, traceroute, dig/nslookup — network diagnostics
  • ip addr / ifconfig — ดู network interfaces
  • nc (netcat) — TCP/UDP connections, port scanning

Disk Management

  • df -h — disk space usage per filesystem
  • du -sh * — directory sizes
  • lsblk — list block devices
  • mount/umount — mount filesystems
  • fdisk/parted — partition management

User & Group Management

  • useradd/userdel/usermod — manage users
  • groupadd/groupmod — manage groups
  • /etc/passwd, /etc/shadow, /etc/group — user/group databases
  • sudo — execute as another user, /etc/sudoers config ด้วย visudo

Performance Monitoring

  • top/htop — CPU, memory per process
  • vmstat — virtual memory, CPU, I/O stats
  • iostat — disk I/O statistics
  • free -h — memory usage
  • sar — 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, priority
  • logrotate — 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

Related Skills

  • Docker — containerization บน Linux primitives
  • Git — version control ที่ใช้บน shell ทุกวัน