Hack 35. Display current time in the prompt
by Ramesh
In the PS1 environment variable, you can directly execute any Linux command, by specifying in the format $(linux_command). In the following example, the command $(date) is executed to display the current time inside the prompt.
- ramesh@dev-db ~> export PS1="\u@\h [\$(date +%H:%M:%S)]> "
- ramesh@dev-db [11:09:56]>
You can also use \t to display the current time in the hh:mm:ss format as shown below:
- ramesh@dev-db ~> export PS1="\u@\h [\t]> "
- ramesh@dev-db [12:42:55]>
You can also use \@ to display the current time in 12-hour am/pm format as shown below:
- ramesh@dev-db ~> export PS1="[\@] \u@\h> "
- [04:12 PM] ramesh@dev-db>
当前内容版权归 Ramesh Natarajan 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Ramesh Natarajan .