You are on page 1of 3

You can link 2 sessions together and have them behave independently (a bit like screen -x) using

the -t option of the new-session command: $ tmux new-session -d -s "session1" $ tmux new-session -s "session2" -t "session1" What Is Tmux tmux is a terminal multiplexer: it enables a number of terminals, each running a separate program to be created, accessed and controlled from a single screen. The definition above, taken from the tmux website, is clear: from one terminal w indow we can start and control a number of other terminals and in each of them r un a different application or a different instance of an application. tmux is developed on a client-server model. This brings into the game the concep t of sessions. A session is stored on the server which holds the representation of a window. Each window can be linked to multiple sessions and moved between th em. On the other hand, multiple clients can be attached to each session. So, one or more users can connect to a tmux session from different computers and they share the same information on the window. This is extremely useful in teaching or col laborating since the users sharing a tmux session see the same information on th eir terminal windows. Connecting to a tmux session is done by starting the application with the follow ing command: tmux attach <session_name> When one user wants to end the terminal sharing feature, the following command i s used: tmux detach How to Install Tmux tmux runs on Linux and Mac. At the moment of writing this article, I am not awar e of a Windows version of the application. For the majority of Linux distributions, there is a package in their repositorie s: Ubuntu Suse On Arch (which I use), installation is simply a matter of running the following command: sudo pacman -S tmux After installation, you can start tmux by issuing the command tmux in a terminal window. If you want to have it running automatically for each terminal session, a small bit of configuration is needed: In the Settings menu go to Edit Current Profile and set the Command field to tmu x as in the screenshot below: tmux settings If you are on Mac, iTerm2 comes with tmux installed, and to start it, you should issue the command: tmux. Features After installation, if you start a terminal window, the only new thing you ll notice is the presence of a status line at the bottom of the screen: terminal with tmux Let s take a look at the most common features. For a list of complete features, see the links at the end of this article. Creating Panes Or, in other words, splitting the main window. First of all, I must say that eac h tmux command is prefixed using the following key combination: <Ctrl-b>. This c an be changed, but we will learn how to configure and customize tmux later on. So, in order to split a window vertically (or in right and left panes) the follo wing command should be used: <Ctrl-b>%

and to split the window in horizontal panes you can use: <Ctrl-b>" And the result should look like following: splitting windows Moving From One Pane to Another and Positioning Panes In order to move the cursor from one pane to the other (activating panes), the a rrow keys are used. The command looks like this: <Ctrl-b>[Up, Down, Right, Left] If you want to go to the previously active pane, you can use the following comma nd: <Ctrl-b>; Also, if you are not satisfied with the position of a pane, you can rotate the p anes using the command: <Ctrl-b><Ctrl-o> Resizing Panes Once created, you can change each panes size, in one cell step, using: <Ctrl-b><Ctrl-Up[Down][Left][Right]> or in five cells step using: <Ctrl-b><Meta-Up[Down][Left][Right]> Closing a Pane When you want to close the current pane you can use: <Ctrl-b>x Create a New Window Sometimes you may want to create another window, for example, to work on another project. This window might contain a completely different set of panes with dif ferent programs in each of them. To do so, issue the following command: <Ctrl-b>c Then if you want to switch to the next window you can use: <Ctrl-b>n And you can switch to the previous window by using: <Ctrl-b>p Or you might select the window interactively with: <Ctrl-b>w Closing a Window In order to close the currently opened window, you use: <Ctrl-b>& Copy Mode Suppose you have issued a command on the terminal and the output of the command does not fit in one screen, so you ll need to scroll up in order to see the entire o utput. If you try pressing the Up key, this won t scroll you up, as it will only sho w you your command history. To scroll up the screen, use the following command: <Ctrl-b>[ And then hit one of the following keys: Up, Down, PgUp or PgDn to scroll up or d own. Also, when in this mode you can copy text from the history and then paste it wit h: <Ctrl-b>] In order to exit this insert mode, just hit esc. Now there are a lot of other commands bound to various keys. You can list all of the key bindings by issuing: <Ctrl-b>? Configuring Tmux tmux is highly configurable. The configuration file is either /etc/tmux.conf for system wide settings or (recommended) ~/.tmux.conf for user specific settings. Change the Prefix Key One of the first things that most users change is the mapping of the prefix key (since <Ctrl-b> doesn t seem to be so handy). Most users change it to <Ctrl-a>. This can be done like so:

set -g prefix C-a unbind C-b bind C-a send-prefix The -g option in the first command tells tmux that this is a global option, mean ing this is set for all windows and sessions. Change the Key Bindings Some users may prefer Vi or Emacs like bindings for the key actions. This is don e using: set -g status-keys vi setw -g mode-keys vi The setw command, sets the option for the window (affects all the panes in a win dow). Status Line You can perform various configurations of the status line: you can turn it on or off, you can change its background and foreground color, you can change what in formation is displayed inside it, etc. To turn the status bar off, issue the following command: set -g status off Or you may try something like this: set -g status-bg blue set -g status-fg white setw -g status-left #H:#S at #W:#T which changes the status line background to blue, the text color to white and disp lays to the left of the status bar the hostname of localhost, followed by a colo n and the session name followed by the at string and the window name, a colon, and las tly the pane title. You can also display the status line at the bottom or at the top of the window: set -g status-position [bottom | top] For further information on configuration and other configuration options you can check the options section of the manual. Conclusion I hope you have found this introduction to tmux helpful in improving your termin al workflow. I ve presented here just a few commands that I use most frequently. If you want to learn more, there are several resources that are available. I highly recommend:

You might also like