Exercise
Customizing the Prompt Exercise
Task
Change your prompt for one shell, decide which form you prefer, then keep it.
- Hosts
-
workstation, thenservera
-
Read the current value of PS1
Every character in the result is an escape sequence:
\uis the user,\hthe host,\Wthe working directory shortened to its last segment.echo $PS1 -
Change \W to \w for the full working directory
Move somewhere with a path worth showing.
\Wdisplays onlylog;\wdisplays/var/log.cd /var/log PS1='\u@\h:\w\$ ' -
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_settingsGoing back to
\Wwould show onlydb_settings. Pick whichever you can live with. -
Confirm the change disappears
Log out of
serveraand log back in.exit ssh servera echo $PS1 -
Persist the prompt you prefer
~/.bashrcis read every time you open a new session, so a line added here runs every time.cd ~ vim ~/.bashrcPS1='\u@\h:\w\$ 'exit ssh servera echo $PS1Clean up
rm -rf ~/app