Hide Computer and User Names in Terminal/Command Prompts
I'm setting up a new MacBook, and before recording, I like to hide the generic information in the terminal.
This can be easily achieved by editing shell configuration files like .bashrc
or .zshrc
.
Here's how:
For Bash Users
- Edit the
.bashrc
File: Open your terminal and runnano ~/.bashrc
to edit the Bash configuration file. - Customize the Prompt: Add the following line to the end of the
.bashrc
file:
export PS1="\W \$"
This command changes the prompt to display only the current directory (\W
) followed by a dollar sign ($
). This setting simplifies the prompt to show just the dollar sign ($), removing user or host information.
- Apply the Changes: Save the changes and exit the editor. You may need to reload the
.bashrc
file by typingsource ~/.bashrc
.
Troubleshooting
Depending on your system setup, if changes do not take effect, you might need to add or edit the .bash_profile
to include sourcing .bashrc
. For detailed guidance on when to use .bash_profile
over .bashrc
. You might need to check the docs if you are struggling with this.
For Zsh Users
- Edit the
.zshrc
File: Open the Zsh configuration file in the terminal by runningnano ~/.zshrc
. - Modify the Prompt: At the end of the
.zshrc
file, add:
export PS1="\$ "
This setting simplifies the prompt to show just the dollar sign ($
), removing any user or host information.
3. Save and Source: After saving the file, apply the changes by sourcing it with source ~/.zshrc
.
I hope this helped!