I was wondering if it was possible to add timestamps to terminal prompts, and if so, how could I achieve this?
Add this line to the .bashrc file
So the output will be something like:
Instead of adding the date to the prompt itself, you could add the date just before your prompt by placing the following line at the top of your
In its current form it will work on anyone's system without amendment as it reads the
Since I don't have enough reputation points to add a comment to the answer to improve it. It would seem that the only way I can add information is to create a second answer. So, I will repeat what was said as the answer and build on that.
Edit the .bashrc file for the user that you want to have the date stamp modified for.
If you see "user@host:~$" you're in your current user's home directory. The .bashrc file is a hidden file since it is prefixed with the dot ".". To see it in a list you will need to use a long listing.
You can use "ls -a" and you should then see the ".bashrc" file.
Edit the file with a text editor. For exmaple, "nano .bashrc", "vim .bashrc", "vi .bashrc", "pico .bashrc" or whatever editor you wish to use.
If you want to script this and plan on adding it to many shells for many users it may be beneficial to use the "echo" command in conjunction with the append ">>" operator. For example,
If you use that method be sure that you are in the current working directory of the user that you wish to modify it for. To check this you can use the "pwd" or print working directory command.
If you don't like the extra space between the "]" end bracket and the username just use this very slightly modified regex:
Use this if you're directly editing the file.