在 CentOS 系统中,使用 nohup 命令运行程序时,默认情况下,日志文件中的时间戳可能不会显示。但是,你可以通过以下方法在日志文件中添加时间戳:
nohup 命令将程序的输出重定向到一个文件,并使用 script 命令为输出添加时间戳。例如,如果你要运行名为 your_command 的程序,可以使用以下命令:nohup script -q -c "your_command" output.log &
这将在 output.log 文件中记录带有时间戳的输出。-q 选项表示静默模式,-c 选项表示执行指定的命令。
nohup 命令将程序的输出重定向到一个文件,并使用 tee 命令为输出添加时间戳。例如:nohup your_command | tee -a output.log
然后,在另一个终端窗口中运行以下命令,以每秒向 output.log 文件添加一个时间戳:
while true; do date >> output.log; sleep 1; done
这将在 output.log 文件中记录带有时间戳的输出。
无论使用哪种方法,你都可以使用 tail 命令查看 output.log 文件中的带有时间戳的日志:
tail -f output.log
这将实时显示 output.log 文件中的新内容。