Two-Line Prompt

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:

  1. Open your terminal and edit the .bashrc or .zshrc file (depending on whether you’re using Bash or Zsh).
    • Use cd ~ then ls -a to see which your system uses.
      • For Bash:
        Open the .bashrc file (for most Linux distributions or WSL): nano ~/.bashrc
      • For Zsh:
        Open the .zshrc file (for Zsh users): nano ~/.zshrc
  2. Modify the PS1 variable. Find the line that starts with PS1= 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:
    • \n or % creates a new line.
    • \u or %n displays the username.
    • \h or %m shows the hostname (can be replaced with just the machine name).
    • \w or %~ shows the current working directory (PWD).
    • $ is the default command prompt symbol for a regular user (you can change it to # for root).
  3. Save and exit:
    • In nano, press CTRL + O to save and CTRL + X to exit.
  4. Apply the changes:
    • After editing the .bashrc or .zshrc, run the following command to apply the changes immediately without restarting the terminal: source ~/.bashrc # For Bash source ~/.zshrc # For Zsh

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

  1. Open a terminal.
  2. Create the .tmux.conf file: You can create the file using any text editor. For example, with nano ~/.tmux.conf
  3. Add the configuration: In the .tmux.conf file, add this line to set the default terminal type: set -g default-terminal "xterm-256color"
  4. Save the file:
    • In nano, press CTRL + O to save, then ENTER to confirm the filename.
    • Press CTRL + X to exit the editor.
  5. Apply the configuration: After creating or editing your ~/.tmux.conf file, you need to apply the changes to your current tmux session: tmux source-file ~/.tmux.conf Alternatively, you can simply restart your tmux session.

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.

Similar Posts

  • Ubuntu Samba Server

    If you need to create a shared drive on an Ubuntu Server that Windows and Linux users can access, SAMBA is the perfect solution. This article will guide you through installing SAMBA, configuring a shared folder, and setting up user permissions. Step…

  • Ubuntu Server Programs

    This is list of programs I use on my Ubuntu Servers with some very basic information. Some of my favorite and most useful Ubuntu Server programs include Network-Tools, Ranger, TMUX, and CMUS for efficient terminal-based management. Network-Tools helps with quick network diagnostics,…

  • TMUX

    TMUX is an easy to use Terminal Multiplexer where users can split the Terminal CLI (Command Line Interface) into multiple mini Terminals. Here’s a TMUX Cheat Sheet with essential tmux commands: Installing tmux The following command installs tmux from the snap repositories….