Exercise

Customizing the Prompt Exercise

Task

Change your prompt for one shell, decide which form you prefer, then keep it.

Hosts
workstation, then servera
  1. Read the current value of PS1

    Every character in the result is an escape sequence: \u is the user, \h the host, \W the working directory shortened to its last segment.

    echo $PS1
  2. Change \W to \w for the full working directory

    Move somewhere with a path worth showing. \W displays only log; \w displays /var/log.

    cd /var/log
    PS1='\u@\h:\w\$ '
  3. Judge the result

    A full path is informative until it eats half the line. Create a deeply nested directory and see.

    mkdir -p ~/app/backend/config/db_settings
    cd ~/app/backend/config/db_settings

    Going back to \W would show only db_settings. Pick whichever you can live with.

  4. Confirm the change disappears

    Log out of servera and log back in.

    exit
    ssh servera
    echo $PS1
  5. Persist the prompt you prefer

    ~/.bashrc is read every time you open a new session, so a line added here runs every time.

    cd ~
    vim ~/.bashrc
    PS1='\u@\h:\w\$ '
    exit
    ssh servera
    echo $PS1

    Clean up

    rm -rf ~/app