Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 系統管理必備:常用命令速查與實戰範例

編輯:Linux 教學

前言

在 Linux 系統日常運維與開發中,熟練掌握核心命令能大幅提升效率。本文整理了過濾進程、查看磁碟空間、統計日誌等高頻場景的實用命令,並附上實戰範例,幫助你快速解決常見問題。

一、 進程過濾與查找

排除特定進程

使用 grep -v 反向匹配,可過濾掉不需要的進程。例如查找 PHP 進程但排除 php-cgi:

ps aux | grep php | grep -v php-cgi

二、 磁碟與檔案大小查看

目錄大小統計

du -sh 以人類可讀格式顯示目錄總大小:

du -sh iphone_newimg/

檔案系統空間使用情況

df -ah 顯示所有檔案系統(含虛擬系統)的磁碟使用量:

df -ah

三、 文字與日誌分析技巧

統計字串出現次數

結合 grep 與 wc -l 計算特定字串行數:

cat a.txt | grep /dev/ | wc -l

Awk 擷取日誌欄位並統計

以空格為分隔符,提取第 9 欄(來源 URL)並統計 Google 來源:

awk '{print $9}' access_log.2012-06-26 | grep 'https://www.google' | wc -l

統計特定下載頁面點擊:

awk '{print $5}' access_log.2012-06-27 | grep '-downloading.html' | wc -l

正則表達式進階匹配

統計機型頁面(支援正則)點擊:

awk '{print $5}' access_log.2012-06-27 | grep '^/phone/[0-9a-zA-Z_]*.html' | wc -l

統計關鍵詞下載頁面來源:

awk '{print $5}' access_log.2012-06-27 | grep '^/download/[0-9a-zA-Z-]*.html' | wc -l

小結

這些命令組合展示了 Linux 管道與文字處理工具的強大威力。實際運維中,善用 awk、grep、wc 等工具,能快速從海量日誌中提取關鍵指標,為系統優化與業務分析提供數據支撐。

Copyright © Windows教程網 All Rights Reserved