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).
Can anyone help? Thanks.
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.
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
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'
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.