3

I want the prompt of all users to output date and time, and in file /etc/bash.bashrc I set:

PS1='\D{%Y%m%d}-\t~\u@\h \$ '

I reboot the system, and after I open a terminal, I see that my prompt has not changed.

What file should I adjust to have the prompt of all users set as I defined above?

2
  • 2
    Of course you realize that any user own personal setting in whatever .bashrc* of their home directory will override your global setting.
    – MC68020
    Commented Sep 23, 2020 at 8:51
  • At least in Ubuntu, every user has .bashrc which sets PS1 by default. See /etc/skel/.bashrc for an example. Commented Sep 23, 2020 at 9:51

1 Answer 1

3

On my system the PS1 is overwritten again by the bashrc-script in the home folder, in ~/.bashrc. Try adding it to this file. By the way, the order in which those and other init files are evaluated is described in the man page in the sections FILES and INVOCATION.

Edit: you can debug the startup process of bash to check whether my diagnosis is correct by running bash -x.

To solve it being shown to all users, you can only edit the per-user config in the skeleton dir /etc/skel/.bashrc, then your changes to PS1 will be available to newly created users. This will not affect already created users, which have the PS1-overwriting .bashrc. For those you have to edit (or perhaps ask those users to edit) the per-user configs in ~user/.bashrc., adding your change or deleting the PS1-overwriting command.

5
  • Does your Bash manual also mention /etc/bash.bashrc?
    – fra-san
    Commented Sep 23, 2020 at 8:58
  • Yes, certainly. Check man bash
    – alphanum
    Commented Sep 23, 2020 at 9:23
  • 1
    Are you on Debian (or a derivative)? I think Debian adds a mention to bash.bashrc, which instead does not appear in most of the other manuals, e.g. that from The Linux man-pages Project, the upstream documentation itself (both Texinfo an man) and that from other distributions (I am on Arch, no mention of that file despite it being used).
    – fra-san
    Commented Sep 23, 2020 at 9:51
  • Again, yes, I use debian (or ubuntu at work). I am very surprised to hear that my manpage seems to have been patched by the distro. This info should really be a basic part of the upstream bash documentation!
    – alphanum
    Commented Sep 23, 2020 at 12:13
  • 1
    The use of /etc/bash.bashrc depends on a compilation option, it is not always-on. I guess it should be up to the distributions to document it when appropriate, and probably Debian stands out positively in this respect. (This answer and its comments have more details and a bit of... debate on the subject).
    – fra-san
    Commented Sep 23, 2020 at 12:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .