如何查看终端的运行时间?(Ubuntu用户)

时间:2022-08-17 15:16:19

So I began working in terminal (with tmux) this morning and forgot the hour when I began. I need to know the time when I started the terminal (or tmux) or the running time of the terminal (or tmux).

所以今天早上我开始在tmux的终端工作,忘记了我开始工作的时间。我需要知道何时启动终端(或tmux)或终端(或tmux)的运行时间。

Can anyone help? Thanks.

谁能帮忙吗?谢谢。

2 个解决方案

#1


2  

ps -eo '%t %c' | grep tmux

should give you the running time of your tmux. Of course, you can also grep for your terminal process directly.

应该给你tmux的运行时间。当然,您也可以直接为您的终端进程进行grep。

#2


1  

If you're setting $PS1 in .bashrc, you can incorporate the date command into this variable--if you do this in the simplest way, it will show you the time you started the shell. If you want to show both the time you started, you can mix that technique with the one described here: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html

如果在.bashrc中设置$PS1,则可以将date命令合并到该变量中——如果以最简单的方式进行此操作,它将显示启动shell的时间。如果您想同时显示启动的时间,您可以将该技术与下面描述的技术混合使用:http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html

Again, the simple version:

再一次,简单的版本:

PS1="Shell started at `date` \$ "

The complex version might start with that, but end with running another date invocation. Obviously, you want to tune the arguments to show a more reasonable time, like date +'%H:%M:%S'

复杂的版本可能从这个开始,但以运行另一个日期调用结束。显然,您希望调整参数以显示更合理的时间,比如日期+'%H:%M:%S'

Edit: Both the start time and the current time use command substitution (to run a command and get the string). The difference is when they are run--the former is run when the shell starts, and the latter is run at every prompt. The latter version is escaped with a backslash, so the command substitution is not executed immediately (but rather, it's executed every time the prompt shows).

编辑:开始时间和当前时间都使用命令替换(运行命令并获取字符串)。区别是当它们运行时——前者在shell启动时运行,而后者在每个提示符下运行。后一个版本使用反斜杠进行转义,因此命令替换不会立即执行(而是每次提示符出现时执行)。

#1


2  

ps -eo '%t %c' | grep tmux

should give you the running time of your tmux. Of course, you can also grep for your terminal process directly.

应该给你tmux的运行时间。当然,您也可以直接为您的终端进程进行grep。

#2


1  

If you're setting $PS1 in .bashrc, you can incorporate the date command into this variable--if you do this in the simplest way, it will show you the time you started the shell. If you want to show both the time you started, you can mix that technique with the one described here: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html

如果在.bashrc中设置$PS1,则可以将date命令合并到该变量中——如果以最简单的方式进行此操作,它将显示启动shell的时间。如果您想同时显示启动的时间,您可以将该技术与下面描述的技术混合使用:http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html

Again, the simple version:

再一次,简单的版本:

PS1="Shell started at `date` \$ "

The complex version might start with that, but end with running another date invocation. Obviously, you want to tune the arguments to show a more reasonable time, like date +'%H:%M:%S'

复杂的版本可能从这个开始,但以运行另一个日期调用结束。显然,您希望调整参数以显示更合理的时间,比如日期+'%H:%M:%S'

Edit: Both the start time and the current time use command substitution (to run a command and get the string). The difference is when they are run--the former is run when the shell starts, and the latter is run at every prompt. The latter version is escaped with a backslash, so the command substitution is not executed immediately (but rather, it's executed every time the prompt shows).

编辑:开始时间和当前时间都使用命令替换(运行命令并获取字符串)。区别是当它们运行时——前者在shell启动时运行,而后者在每个提示符下运行。后一个版本使用反斜杠进行转义,因此命令替换不会立即执行(而是每次提示符出现时执行)。