tmux working with split terminal


tmux working with split terminal

Tmux is a terminal multiplexer for linux systems. Tmux allows multiple terminal sessions can be accessed within a single window. Tmux is used for running more than one program in the same terminal at the same time. We can also use it to detach processes/programs from their controlling terminals. Tmux allows SSH sessions to remain active without being visible.

How to install Tmux on ubuntu?

  • Open the terminal and type the below command and install Tmux.
    sudo apt-get install tmux
    

How to install Tmux on Cent OS and Fedora?

  • Open the terminal and type the below command and install Tmux.
    sudo yum install tmux
    

How to install Tmux on macOS?

  • Open the terminal and type the below command and install Tmux.
    sudo brew install tmux
    

Lets get started with Tmux

  • To start the Tmux we have to simply execute below command in terminal. After execution of the command you will see a green page at the bottom of the terminal.
    tmux
  • Let's do some magic with Tmux. Now, press Ctrl + B and then press % (i.e Shift + 5 ). Now, you can see a vertical split in the terminal window.
  • To close the current sesstion just type  exit .
  • To get help about Tmux press Ctrl + B and 
  • To split horizontally in tmux then press Ctrl + B and then press " (i.e Shift + ' ).
  • To detach the Tmux then  press  Ctrl + B and then press d

Most common commands for managing Tmux

  • Ctrl+b then c Create a new window (with shell)
  • Ctrl+b then w Choose window from a list 
  • Ctrl+b then 0 Switch to window 0 (by number )
  • Ctrl+b then , Rename the current window
  • Ctrl+b then % Split current pane horizontally into two panes
  • Ctrl+b then " Split current pane vertically into two panes
  • Ctrl+b then o Go to the next pane
  • Ctrl+b then ; Toggle between current and previous pane
  • Ctrl+b then x Close the current pane

      Creating named sessions in Tmux

      • By defaut when we create session in Tmux it will name the session with a number starting from zero.
      • But, we can also create the session with name also. We can do it with below command.
        tmux new -s my_new_session

      List available sessions in Tmux

      • To list available session in Tmux execute the below command in the terminal
        tmux ls

            Kill a session in Tmux

            • To list available session in Tmux execute the below command in the terminal
              tmux kill-session -t my_new_session
            • We have to give session name instead "my_new_session". If we do not give name to session then by default an integer will be given as a session name.

            Customizing Tmux

            • All the configuration of tmux is loaded from file ~/.tmux.conf . We can customize it as per our requirements.
            • Let's do some customizations
              # Improve colors
              set -g default-terminal 'screen-256color'
              
              # Set scrollback buffer to 20000
              set -g history-limit 20000
              
              # Customize the status line
              set -g status-fg  green
              set -g status-bg  black
              
               

            References:

            1. https://github.com/tmux/tmux/wiki
            2. https://gist.github.com/afair/3489752

             

                    Read Prev: python reading and writing files

                    Blog Archive