bash PS1 提示中的短日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9200862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
short date in bash PS1 prompt
提问by fergusdawson
You can use \d in the your PS1 confuration to display a long date ie. Tues 18 May, but how can I get it to display it in a format like 18.05.2012 for example?
您可以在 PS1 配置中使用 \d 来显示长日期,即。5 月 18 日星期二,但我怎样才能让它以 18.05.2012 等格式显示呢?
采纳答案by Mithrandir
Try this:
尝试这个:
PS1="$(date +%d.%m.%Y) > "
export PS1
回答by FatalError
Try including \D{%d.%m.%Y}. You can use any time format suppoorted by strftime(3).
尝试包括\D{%d.%m.%Y}. 您可以使用支持的任何时间格式strftime(3)。
回答by martineg
Use \D{format} where formatis a strftime format code. For example:
使用\D{format} 其中format是 strftime 格式代码。例如:
$ export PS1='\D{%d.%m.%Y}$ '
08.02.2012$
回答by user4111240
Rather than telling the shell to execute the date command each time, you would rather use the built-in format. Hence you can also use (though a little variation from what you have asked)
与其告诉 shell 每次都执行 date 命令,不如使用内置格式。因此,您也可以使用(尽管与您所要求的略有不同)
\D{%F %T}
\D{%F %T}
to give you date and time. date in format : YYYY-MM-DD and time in format hh:mm:ss.
给你日期和时间。日期格式:YYYY-MM-DD 和时间格式为 hh:mm:ss。
回答by marwansherin
you can try this that display time:
你可以试试这个显示时间:
$ PS1="\n\t \u@\h:\w# "
08:18:57 user@localhost:/home/user#

