如何将最后一个命令的挂墙时间放在 Bash 提示符中? [英] How can the last command's wall time be put in the Bash prompt?

查看:16
本文介绍了如何将最后一个命令的挂墙时间放在 Bash 提示符中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Bash 提示中嵌入最后一个命令的已用时间?我希望看起来像这样:

Is there a way to embed the last command's elapsed wall time in a Bash prompt? I'm hoping for something that would look like this:

[last: 0s][/my/dir]$ sleep 10
[last: 10s][/my/dir]$

背景

我经常运行长时间的数据处理工作,了解它们花费了多长时间非常有用,这样我就可以估计未来工作需要多长时间.对于非常常规的任务,我会继续使用适当的日志记录技术严格记录这些信息.对于不太正式的任务,我只会在命令前加上 time.

I often run long data-crunching jobs and it's useful to know how long they've taken so I can estimate how long it will take for future jobs. For very regular tasks, I go ahead and record this information rigorously using appropriate logging techniques. For less-formal tasks, I'll just prepend the command with time.

如果能自动time每一个交互式命令,并且将时间信息打印在几个字符而不是 3 行中,那就太好了.

It would be nice to automatically time every single interactive command and have the timing information printed in a few characters rather than 3 lines.

推荐答案

你可以利用这个 zsh 借来的钩子来处理 bash:http://www.twistedmatrix.com/users/glyph/preexec.bash.txt

You could utilize this zsh-borrowed hook for bash: http://www.twistedmatrix.com/users/glyph/preexec.bash.txt

使用此钩子完成计时(Mac OS X):使用 Growl 监控长时间运行的 shell 命令

Timing done with this hook (Mac OS X): Use Growl to monitor long-running shell commands

这篇关于如何将最后一个命令的挂墙时间放在 Bash 提示符中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆