gpt4 book ai didi

linux - 在 linux shell 中发出命令时打印当前时间和日期

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:41 25 4
gpt4 key购买 nike

我试图在每次通过命令行在 sift linux (ubuntu 14) 上发出命令时将当前时间和日期打印到屏幕上。

例如

sansforensics@siftworkstation:$ fdisk -l image.dd 

sansforensics@siftworkstation:$ output of command

current time and date


sansforensics@siftworkstation:$

我不是在找

start_time=`date +%s`
<command-to-execute>
end_time=`date +%s`
echo execution time was `expr $end_time - $start_time` s.

它打印出命令运行所花费的时间,每次发出命令时我都会查找当前日期和时间。

最佳答案

您正在此处寻找 PROMPT_COMMAND:

PROMPT_COMMAND='date'

根据man bash:

PROMPT_COMMAND
If set, the value is executed as a command prior to issuing each primary prompt.

关于linux - 在 linux shell 中发出命令时打印当前时间和日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29217117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com