How to customize a prompt?

0141

You can customize the terminal prompt by modifying the shell configuration file. The method varies depending on the shell you are using. Here are examples for two common shells: Bash and Zsh.

For Bash

  1. Open the .bashrc file in your home directory:

    nano ~/.bashrc
  2. Look for the line that starts with PS1=. This variable defines the primary prompt string.

  3. Modify the PS1 variable to customize your prompt. For example:

    PS1='\u@\h:\w\$ '
    • \u - username
    • \h - hostname
    • \w - current working directory
    • \$ - shows # for root and $ for regular users
  4. Save the file and exit the editor.

  5. Apply the changes by running:

    source ~/.bashrc

For Zsh

  1. Open the .zshrc file in your home directory:

    nano ~/.zshrc
  2. Look for the line that starts with PROMPT=. This variable defines the prompt.

  3. Modify the PROMPT variable to customize your prompt. For example:

    PROMPT='%n@%m:%~%# '
    • %n - username
    • %m - hostname
    • %~ - current working directory
    • %# - shows # for root and % for regular users
  4. Save the file and exit the editor.

  5. Apply the changes by running:

    source ~/.zshrc

After following these steps, your terminal prompt will reflect the customizations you made.

0 Comments

no data
Be the first to share your comment!