Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

short date in bash PS1 prompt

Tags:

bash

ps1

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?

like image 215
fergusdawson Avatar asked Feb 08 '12 20:02

fergusdawson


People also ask

What does PS1 do in bash?

Here are the different meanings for the different parts of the BASH prompt: PS1 – This is the primary prompt display. This is where you set special characters or important information. PS2 – This is the secondary prompt string.

How do I add a timestamp to a bash prompt?

To display timestamp on command prompt, use the special character \D{} for PS1 shell variable. It is possible to display arbitrary time format by putting a special character based on strftime() function into {} . For more information on special characters, refer to the online manual “STRFTIME(3) man 3 strftime. ”

What is the PS1 variable?

The PS1 variable contains the value of the default prompt. It is used to change the looks and environment of the shell command prompt. Different examples of using the PS1 variable have been shown in this tutorial.

How do I permanently change PS1 in Linux?

In Linux, the PS1 system variable is used to change the prompt setting. To change the Linux prompt permanently, you need to modify the . bashrc file which initializes the interactive shell session whenever the system starts.


Video Answer


2 Answers

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

like image 88
FatalError Avatar answered Oct 12 '22 12:10

FatalError


Try this:

PS1="\$(date +%d.%m.%Y) > " export PS1 
like image 21
Mithrandir Avatar answered Oct 12 '22 12:10

Mithrandir