简体   繁体   English

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

[英]How can I see the running time of the terminal? (Ubuntu user)

So I began working in terminal (with tmux) this morning and forgot the hour when I began. 因此,今天早上我开始在码头(与tmux合作)中工作,却忘记了开始的那一小时。 I need to know the time when I started the terminal (or tmux) or the running time of the terminal (or tmux). 我需要知道启动终端(或tmux)的时间或终端(或tmux)的运行时间。

Can anyone help? 有人可以帮忙吗? Thanks. 谢谢。

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

should give you the running time of your tmux. 应该给你tmux的运行时间。 Of course, you can also grep for your terminal process directly. 当然,您也可以直接为您的终端进程使用grep。

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. 如果在.bashrc中设置$PS1 ,则可以将date命令合并到该变量中-如果以最简单的方式执行此操作,它将显示启动外壳程序的时间。 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 如果要同时显示开始时间,则可以将该技术与此处描述的方法混合使用: 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. 复杂的版本可能以此开始,但以运行另一个date调用结束。 Obviously, you want to tune the arguments to show a more reasonable time, like date +'%H:%M:%S' 显然,您想调整参数以显示更合理的时间,例如date +'%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). 后一个版本以反斜杠转义,因此命令替换不会立即执行(而是在每次提示显示时执行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM