
To have your terminal show the input command on its own line, with your username and the current working directory (PWD) on a separate line, you will need to modify the shell prompt (PS1) in your terminal configuration.
Here’s how you can customize the prompt for this behavior:
- Open your terminal and edit the
.bashrcor.zshrcfile (depending on whether you’re using Bash or Zsh).- Use
cd ~ then ls -ato see which your system uses.- For Bash:
Open the.bashrcfile (for most Linux distributions or WSL):nano ~/.bashrc - For Zsh:
Open the.zshrcfile (for Zsh users):nano ~/.zshrc
- For Bash:
- Use
- Modify the
PS1variable. Find the line that starts withPS1=and change it to: For Bash (in.bashrc):PS1='\n\u@\h:\w\n$ 'For Zsh (in.zshrc):PS1='%n@%m:%~\n$ 'Explanation of the components:\nor%creates a new line.\uor%ndisplays the username.\hor%mshows the hostname (can be replaced with just the machine name).\wor%~shows the current working directory (PWD).$is the default command prompt symbol for a regular user (you can change it to#for root).
- Save and exit:
- In nano, press
CTRL + Oto save andCTRL + Xto exit.
- In nano, press
- Apply the changes:
- After editing the
.bashrcor.zshrc, run the following command to apply the changes immediately without restarting the terminal:source ~/.bashrc # For Bash source ~/.zshrc # For Zsh
- After editing the
Now your terminal will look like this:
user@hostname:/current/directory
$
This will separate the prompt into two lines:
- The first line shows your username, hostname, and current working directory.
- The second line shows the prompt (
$for regular user,#for root) where you can type your command.
To make it so that tmux will use the same Two-Line Prompt style:
Create the ~/.tmux.conf File
- Open a terminal.
- Create the
.tmux.conffile: You can create the file using any text editor. For example, withnano ~/.tmux.conf - Add the configuration: In the
.tmux.conffile, add this line to set the default terminal type:set -g default-terminal "xterm-256color" - Save the file:
- In nano, press
CTRL + Oto save, thenENTERto confirm the filename. - Press
CTRL + Xto exit the editor.
- In nano, press
- Apply the configuration: After creating or editing your
~/.tmux.conffile, you need to apply the changes to your currenttmuxsession:tmux source-file ~/.tmux.confAlternatively, you can simply restart yourtmuxsession.
Test Your Prompt
Once you’ve done this, start a new tmux session, and your terminal prompt should now properly handle newlines for the two-line prompt style.
tmux
Why This Works:
By setting default-terminal to xterm-256color, you tell tmux to use a terminal type that correctly handles newline characters and other escape sequences in your shell prompt.
