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 ac命令:統計用戶連線時間

編輯:Linux 教學

ac命令讀取/var/log/wtmp記錄,統計用戶登入系統的總連線時間(小時),是系統管理員審計用戶活動的輕量工具。

基本用法

ac                # 顯示所有用戶總連線時間
ac -d             # 按天顯示每日總連線時間
ac -p             # 按用戶顯示個人總連線時間
ac -d -p          # 結合:每日每用戶連線時間

輸出範例

$ ac
       total     5177.47

$ ac -d
Aug 12  total    261.87
Aug 13  total    351.39
Aug 14  total    396.09
...

$ ac -p
ynguo       193.23
yucao         3.35
rong        133.40
hdai         10.52
zjzhu        52.87
total      5178.24

進階選項

選項說明
-w file指定wtmp檔案路徑(預設/var/log/wtmp)
-u user僅統計指定用戶
-g group僅統計指定群組用戶

注意事項

  • 時間單位為小時,含小數點(如0.5 = 30分鐘)。
  • 依賴wtmp完整性,若日誌輪轉或被清空,統計將不準確。
  • 僅統計交互式登入(TTY/SSH),不含su、sudo、cron等非登入會話。
  • 配合last、lastlog可獲取更詳細登入資訊。

ac雖簡單,但在用戶帳號審計、資源使用分析、合規檢查場景下極具參考價值。

Copyright © Windows教程網 All Rights Reserved