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?
Asked
Active
Viewed 2.3k times
6 Answers
74
Try including \D{%d.%m.%Y}
. You can use any time format supported by strftime(3)
.

MiniGod
- 3,683
- 1
- 26
- 27

FatalError
- 52,695
- 14
- 99
- 116
-
5This should be accepted as it uses shell substitution instead of an external command in a subshell. – mcmlxxxvi Nov 25 '15 at 17:35
22
Rather than telling the shell to execute the date command each time, you can use the built-in format:
\D{%F %T}
to give you date and time in this in format: YYYY-MM-DD hh:mm:ss

Rob Bednark
- 25,981
- 23
- 80
- 125

user4111240
- 221
- 2
- 2
19
PS1="\$(date +%d.%m.%Y) > "
export PS1

Rob Bednark
- 25,981
- 23
- 80
- 125

Mithrandir
- 24,869
- 6
- 50
- 66
-
1Better to use the shell substitution as per FatalError answer below. – jzacharuk Sep 26 '17 at 15:57
19
Use \D{format}
where format
is a strftime
format code.
For example:
$ export PS1='\D{%d.%m.%Y}$ '
08.02.2012$
-
-
Depending on your platform, you could put these kind of customizations in ~/.bash_profile which is read when a new interactive shell is started. – martineg Jun 30 '21 at 13:13
5
you can try this that display time:
$ PS1="\n\t \u@\h:\w# "
08:18:57 user@localhost:/home/user#

Romil Patel
- 12,879
- 7
- 47
- 76

marwansherin
- 51
- 1
- 1
0
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

Carolus
- 477
- 4
- 16