熱門分類
載入中…
目錄0%

🐧 Linux 使用技巧:10 個讓你工作效率翻倍的小祕訣

    🐧 Linux 使用技巧:10 個讓你工作效率翻倍的小祕訣

    學會 Linux 不只是會下指令,更重要的是善用它的效率與彈性。以下整理出十個實用技巧,從檔案查找、服務監控、到自動化任務,幫助你快速掌握系統核心。

    📑 目錄


    1️⃣ 快速查找與統計檔案

    # 查找特定檔案
    find /etc -name "*.conf"
    
    # 統計目錄大小
    du -sh /var/log/*
    
    # 搜尋關鍵字內容
    grep -rn "error" /var/log/

    善用 finddugrep 能快速定位問題來源與異常檔案。

    2️⃣ 一行檢視系統資源

    free -h        # 記憶體使用狀況
    df -h          # 磁碟使用率
    uptime         # 系統運行時間與負載
    lscpu          # CPU 規格
    lsblk          # 儲存裝置結構

    3️⃣ 查看服務與啟動狀態

    systemctl status sshd
    systemctl enable nginx
    systemctl list-units --type=service --state=failed

    利用 systemctl 可快速檢查系統開機啟動服務狀態。

    4️⃣ 快速網路除錯指令

    ip a                 # 查看網卡
    ping -c 4 8.8.8.8     # 測試連線
    ss -tulnp | grep 80   # 顯示監聽埠
    dig google.com        # DNS 查詢
    traceroute 8.8.8.8    # 路由追蹤

    5️⃣ 防火牆與連線監控

    # firewalld
    sudo firewall-cmd --list-all
    sudo firewall-cmd --add-port=22/tcp --permanent
    
    # netstat / ss
    sudo ss -s
    sudo netstat -antup

    6️⃣ 使用 systemd 自動化任務

    # 建立排程服務
    sudo systemctl edit backup.timer
    # 內容:
    [Timer]
    OnCalendar=*-*-* 02:00:00
    Persistent=true
    [Install]
    WantedBy=timers.target
    
    # 啟用
    sudo systemctl enable --now backup.timer

    7️⃣ 監控系統效能(top / htop)

    top          # 即時監控
    htop         # 互動式視圖(需安裝)
    iotop        # I/O 操作監控

    建議搭配 nmondstatvmstat 進行進階分析。

    8️⃣ 管理使用者與權限

    sudo adduser devuser
    sudo passwd devuser
    sudo usermod -aG sudo devuser
    chmod 750 /srv/data
    chown devuser:devuser /srv/data

    9️⃣ 分析與整理日誌

    journalctl -xe         # 查看系統錯誤
    journalctl -b -p warning
    tail -n 100 /var/log/messages
    goaccess /var/log/nginx/access.log -o report.html --log-format=COMBINED

    🔟 提升安全性與穩定性

    # 限制 SSH 登入
    sudo vim /etc/ssh/sshd_config
    PermitRootLogin no
    PasswordAuthentication no
    
    # 自動封鎖暴力登入
    sudo apt install fail2ban -y
    sudo systemctl enable --now fail2ban

    📘 結語

    這 10 個技巧幾乎涵蓋了 Linux 系統維運的核心:檔案、網路、服務、安全。若能熟練這些操作,你就能快速定位問題、提升效能,讓 Linux 成為真正的高效率工具。

    🔗 延伸閱讀

    — WWFandy・系統與網路筆記

    🔗 分享這篇 LINE Facebook X

    沒有留言:

    字級