문제

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?

도움이 되었습니까?

해결책

Try this:

PS1="\$(date +%d.%m.%Y) > "
export PS1

다른 팁

Try including \D{%d.%m.%Y}. You can use any time format suppoorted by strftime(3).

Use \D{format} where format is a strftime format code. For example:

$ export PS1='\D{%d.%m.%Y}$ '
08.02.2012$

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)

\D{%F %T}

to give you date and time. date in format : YYYY-MM-DD and time in format hh:mm:ss.

you can try this that display time:

$ PS1="\n\t \u@\h:\w# "

08:18:57 user@localhost:/home/user#

I'm not sure how to apply this to PS1 specifically (maybe someone can edit this question to replace this part with the best working bit from other questions).

BUT you can get short date formatted according to your current locale with:

date +%x
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top