How to hide computer name and user name in terminal command prompt
Solution 1:
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.
Edit:
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.
Solution 2:
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.
- Open the preferences in the terminal (top right)
- Then go into the shell tab
- Then copy/paste the command
export PS1="\W \$"; clear;
- Then restart the terminal and should work
Solution 3:
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.
Solution 4:
Check out this tutorial on how to change your bash prompt.
A very short version (only username and no current path):
PS1="\u$ "
Result: myusername$ cat something.log
Solution 5:
Edit ~/.bash_profile to save your changes to prompt.
nano ~/.bash_profile
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.
source ~/.bash_profile