Linux命令 檢視歷史,並顯示操作時間

2021-10-13 13:13:25 字數 616 閱讀 3882

最終效果如下

在這裡插入描述

linux下可輸入「history」檢視已執行命令歷史。正常是不帶操作時間的,預設只顯示序號和命令。要想顯示操作時間需要做如下配置。

臨時顯示

如需臨時顯示執行時間則輸入「export histtimeformat=』%f %t』」。

1永久生效

如需永久顯示執行時間可通過編輯名為「.bash.rc」的隱藏檔案完成。

按「i」進入編輯狀態並新增如下內容(格式可自行調節),確認無誤後按esc並輸入:x儲存退出。

注意:本例中設定變數名為display date, 並新增上「export histtimeformat=』%f %t』」

#display time

export histtimeformat=』%f %t 』12

在這裡插入描述

使許可權生效

「source ~/.bashrc」

1重啟後再次輸入「history」依然可顯示執行時間。

注意:(1)此修改僅可正確顯示修改後執行命令的時間。

(2)可在命令列加上兩個空格,「export histtimeformat=』%f %t '」,實現示時間和命令之間有間隔,。

在這裡插入描述

Linux檢視歷史命令

今天面試問到怎麼檢視歷史命令,我說用上方向鍵把面試官逗笑了,特此查詢記錄一下。linux中,bash輸入的命令記錄,通過history檢視所有歷史記錄。記錄會存在.bash history 或者root bash history 中,通過echo histfile 使用此命令檢視環境變數 histo...

Linux檢視歷史命令 history

root linux history n root linux history c root linux history raw histfiles 引數 n 數字,意思是 要列出最近的 n 筆命令列表 的意思!c 將目前的 shell 中的所有 history 內容全部消除 a 將目前新增的 hi...

linux檢視歷史命令history

linux的history命令的作用是,記錄執行過的命令。用法 history n n為數字,列出最近的n條命令 c 將目前shell中的所有history命令消除 history raw histfiles a 將目前新增的命令寫入histfiles,預設寫入 bash history r 將hi...