1

Is there a way to use sudo -sbut keeping the current folder name in prompt?

terminal

I want to see jw:documents nescalante$ instead of bash-3.2# when using sudo -s.

Thanks!

lante
  • 318
  • 2
  • 12
  • You start to use other user (root) so you are located in root's home. There is no reason you can't change to the directory you want. Or use full power of sudo and run command directly with sudo w/o need of use root shell – Romeo Ninov Jan 18 '15 at 13:50

1 Answers1

2

When you use sudo -s you obtain a behaviour similar to sudo /bin/bash.
The variable USER is set to root and not anymore to nescalante.

You can put inside your .bashrc or, worst, in your .bash_aliases an IF THEN block to set your prompt when you are the root user.

if [ "$USER" = "root" ]
then
  export PS1="\[\e[36;1m\]\u@\[\e[32;1m\]\h \[\e[34;1m\]\w> \[\e[0m\]"
fi

If you do not want to know that you are root in that shell you can write

  export PS1="\[\e[36;1m\]HowIWantToBe@\[\e[32;1m\]\h \[\e[34;1m\]\w> \[\e[0m\]"

but I strongly suggest to leave notice that you are root. root can delete a system with a single command line, in so many way that you cannot even image :).

Note:

  • If you use a shell different from bash you have to write with a different syntax in a file different from .bashrc.
  • You can search the prompt PS1 value currently in use for your user in your shell starting file (e.g. .bashrc) and copy/modify it as you wish.
  • If you want to know better how sudo and su commands function refer to man pages or give a fast look e.g. here.
Hastur
  • 18,764
  • 9
  • 52
  • 95