How can I hide username and computer in terminal command prompt?
In Terminal it says
Last login: Mon Jan 13 00:00:14 on ttys000 Whatever:~ UserName$
Is it possible to show just the current folder and
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
Change your prompt in your ~/.bashrc file. The example you asked for would be:
export PS1="\W \$"
It would result in the current folder you're in being shown plus a $ for the regular prompt and a # if you're root. Check out this guide for more examples of what you could show in your prompt.
As per one of the comments below, you might need to source your
~/.bashrc from your
~/.bash_profile or even put this code in your
~/.bash_profile instead. You can read this article for a better explanation on which file to use.
I had a similar issue with this but did not get it working at first.
This may of been because I wasn't sudo but either way this works just as well.
export PS1="\W \$"; clear;
\Wis supposed to be working directory path. I think it should actually be lowercase though. However, if you are using the default Mac terminal, you aren't using bash, you are using zsh. try this:
export PS1="%~ $ "Feb 9, 2022 at 20:58
echo "export PS1='$ '" >> ~/.bash_profile . ~/.bash_profile
This will leave just
$ as a prompt. If you want to restore the old prompt, you will need to edit .bash_profile to remove that "export ..." line.
Check out this tutorial on how to change your bash prompt.
A very short version (only username and no current path):
myusername$ cat something.log
Edit ~/.bash_profile to save your changes to prompt.
At the end, add your changes.
# Change prompt export PS1="\W \$ "
Exit, save changes. Hit enter to confirm the file name. Run source to see the change.
Create/Edit your .bash_profile file or your root:
sudo vim ~/.bash_profile
and add this line
export PS1="\W$: "
The space will give you some breathing space in command prompt. After this modification your command prompt will looks like this:
~/.zshrc file to your regular username. You can get your exact username value by executing
whoami in the terminal.
Something like this:
export PS1="[\033[01;32m]\W \$ [\033[00m]"
\W will give you the current folder (\w to include the path too). The brackets set the color codes. So this puts the current folder in green, and then resets the color to white after the prompt.
Mine is: PS1="\W[\033[32m]\$(parse_git_branch)[\033[00m] $ "
:. BTW: I've changed the computer name in System Preferences -> Sharing to MBP. Now my login prompt is very short: