Ctrl+b
c
Create a new window (with shell)Ctrl+b
w
Choose window from a listCtrl+b
0
Switch to window 0 (by number )Ctrl+b
,
Rename the current windowCtrl+b
%
Split current pane horizontally into two panesCtrl+b
"
Split current pane vertically into two panesCtrl+b
o
Go to the next paneCtrl+b
;
Toggle between current and previous paneCtrl+b
x
Close the current pane
When Tmux is started it reads its configuration parameters from ~/.tmux.conf
if the file is present.
Major features include:
- A powerful, consistent, well-documented and easily scriptable command interface.
- A window may be split horizontally and vertically into panes.
- Panes can be freely moved and resized, or arranged into one of four preset layouts.
- Support for UTF-8 and 256-colour terminals.
- Copy and paste with multiple buffers.
- Interactive menus to select windows, sessions or clients.
- Change the current window by searching for text in the target.
- Terminal locking, manually or after a timeout.
- A clean, easily extended, BSD-licensed codebase, under active development.
tmux is part of the OpenBSD base system. The portable version is hosted on SourceForge and runs on Linux, FreeBSD, NetBSD, Solaris and AIX.
tmux depends on libevent 1.4 and a terminfo implementation (normally ncurses).
Interview with Nicholas Marriott on tmux
All in all, tmux is a very nice alternative to screen and it has the great benefit of being in base as of OpenBSD 4.6. If you're still on an older version and want to try out tmux, you can install the package or install a recent snapshot.We recently reported on the fact that tmux was imported into OpenBSD. By now, several changes have gone into the tree, including new features and some fixes from other developers. We spoke with Nicholas Marriott about tmux and his ideas for the future.
OpenBSD Journal: Why did you write tmux when there is well known screen ? Were you a heavy screen user before tmux ? Did it frustrate you into writing tmux ?
nicm@: I was a heavy screen user and I was vaguely unhappy with it. It was another of those programs with a lot of baggage - poor documentation, a strange configuration file and an unintuitive command-line interface. And that isn't mentioning the code.
There were a few things I wanted. In particular, being able to share a single window between multiple terminals, with other windows in the same session but entirely separate. Adding this to screen was implausible; it became one of my goals to have a codebase that was readable and could be extended.
OJ: How long have you worked on it so far ?
nicm@: tmux began with a quick prototype (called "nscr") and a few basic functions. A few months later I started fleshing out the prototype out and published the first version online in late 2007.
Currently, tmux is pretty usable and stable; I think most users could switch from tmux to screen or vice versa without missing too many features from either. There are still many feature requests and a lot of work to be done so I encourage everyone to read the code and send me their patches!
OJ: Can you tell us about how/when tmux got into base and you got your account ?
nicm@: It wasn't something I had expected. Paul Irofti [pirofti@] brought tmux up at the last hackathon and they decided to import it. Theo asked me for my opinion and I preferred to work on it in base: I felt tmux would be improved by being part of OpenBSD, it would add many more expert users and developers, a larger userbase, and a more rigorous development schedule - not to mention being more useful and easier to use than window(1).
OJ: Are you striving for full feature completeness compared to screen ? What screen features are you missing that you still want to add, which will you never add and what does tmux do that screen doesn't ?
nicm@: I don't like to sound like a politician, but that is a difficult question and the answer is "yes and no". I'd like for most people to be able to achieve the same things they can in screen in tmux. But tmux is not intended to be a copy of screen, and it should not behave as screen or have screen features just because screen has them.
At the moment, tmux has most of the major features of screen, but some things are missing - mostly things I didn't use. ;-)
If anyone is feeling itchy, here are a few items from my todo list:
- the ability to bind arbitrary strings to tmux key bindings instead of just keys from terminfo(5);
- make mode key sequences (eg in copy mode) customisable;
- better editing at the command prompt (clear, delete word, etc) and improvements to scroll mode, such as search and better vi keys;
- convert some outside-only commands to work inside tmux (attach, new);
- add many more info() displays;
- commands which expect filenames should expand ~ at the start;
- man page improvements: make sure every command matches the code and vice versa, and split the command list up by use rather than alphabetical order;
- improve terminal support, and find the copy/paste line wrapping problem;
If anyone has more, or has questions, let me know. :-)
OJ: Did the integration into OpenBSD base change anything for you and / or your development process ?
nicm@: Import into OpenBSD has been a good thing: I have received many feature requests, bug reports and code changes. I have to do a bit of work to sync up to make portable releases but tmux was already very portable and cvsps makes the job pretty easy so far.
OJ: What are your future plans for tmux ? What's next on your todo list ?
nicm@: There is a lot of work to be done in many areas, just look at the todo list.
At the moment I'm working on improving the layout code so that it is possible to split both vertically and horizontally. This will make layouts become "layout sets" which you can apply and then adjust.
I think it is pretty awesome and I have about 90% of it complete. Some of it is being tested now, and I hope to finish the whole thing within the next week or so.
Once that is done I'm not sure what I'll look at next. I have some ideas about adding hooks so you can execute commands on certain events (new window created, terminal resized, etc) but I haven't really thought that through too much. I might just spend some time trying to blitz the todo list and my inbox into manageable state. ;-)
Plus at the moment I spend time implementing smaller feature requests and fixing the odd bug.
OJ: Will you be working on other stuff in OpenBSD ? If so, what ?
nicm@: I don't know; I'd like to. At the moment tmux takes most of my time, but it has interested me in related areas such as terminal emulation and ncurses, so I might take a look at what I can do there.
OJ: Thank you, Nicholas, for your time in answering these questions and thanks for a very useful tool.
A tmux Crash Course
I’ve been using tmux for about six months now and it has become just as essential to my workflow as vim. Pane and window management, copy-mode for navigating output, and session management make it a no-brainer for those who live in the terminal (and especially vim). I’ve compiled a list of tmux commands I use daily to help me work more efficiently.
Shortcuts
If a tmux command I mention is bound to a keyboard shortcut by default, I’ll note that in parenthesis.
They’re accessed by entering a key combination called the prefix and then typing a letter.
For example, if you see prefix + d
below, that means you would first hit (and release) Control + b
and
then type d
.
The prefix can also be changed, which I’ll show you how to do later.
Session Management
Sessions are useful for completely separating work environments. I have a ‘Work’ session and a ‘Play’ session;
- in ‘Work’, I keep everything open that I need during my day-to-day development,
- while in ‘Play’, I keep open current open-source gems or other work I hack on at home.
tmux new -s session_name
- creates a new tmux session named session_name
tmux attach -t session_name
- attaches to an existing tmux session named session_name
tmux switch -t session_name
- switches to an existing session named session_name
tmux list-sessions
- lists existing tmux sessions
tmux detach (prefix + d)
- detach the currently attached session
Windows
tmux has a tabbed interface, but it calls its tabs “Windows”. To stay organized, I rename all the windows I use; if I’m hacking on a gem, I’ll name the window that gem’s name. The same thing goes for client applications. That way, I can recognize windows by context and not what application it’s running.
tmux new-window (prefix + c)
- create a new window
tmux select-window -t :0-9 (prefix + 0-9)
- move to the window based on index
tmux rename-window (prefix + ,)
- rename the current window
Panes
Panes take my development time from bland to awesome. They’re the reason I was able to uninstall MacVim and develop solely in iTerm2. I don’t have to switch applications to switch contexts (editing, reading logs, IRB, etc.) - everything I do, I do in a terminal now. People argue that OS X’s Cmd+Tab is just as fast, but I don’t think so.
tmux split-window (prefix + ")
- splits the window into two vertical panes
tmux split-window -h (prefix + %)
- splits the window into two horizontal panes
tmux swap-pane -[UDLR] (prefix + { or })
- swaps pane with another in the specified direction
tmux select-pane -[UDLR]
- selects the next pane in the specified direction
tmux select-pane -t :.+
- selects the next pane in numerical order
Helpful tmux commands
tmux list-keys
- lists out every bound key and the tmux command it runs
tmux list-commands
- lists out every tmux command and its arguments
tmux info
- lists out every session, window, pane, its pid, etc.
tmux source-file ~/.tmux.conf
- reloads the current tmux configuration (based on a default tmux config)
Must-haves
These are some of my must-haves in my tmux config:
# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf
# quick pane cycling
unbind ^A
bind ^A select-pane -t :.+
Workflow
During the day, I’ll work on one or two Rails apps, work on my dotfiles, run irssi, and maybe run vim in another window to take notes for myself. As I mentioned, I run all of this inside one tmux session (named work) and switch between the different windows throughout the day.
When I’m working on any Ruby work specifically, I’ll have a 75%/25% vertical split for vim and a terminal so I can run tests, interact
with git, and code. If I run tests or git diff
and want to see more output than the 25% allots me, I’ll use tmux to swap
the panes and then move into copy mode to see whatever I need to see.
Finally, I run iTerm2 in full-screen mode. Switching between OS X apps for an editor and a terminal is for chumps!
What's next
If you found this article useful, you might also enjoy:
- Seamlessly Navigate Vim and tmux Splits
- tmux Copy and Paste on OS X
- Running Specs from Vim, Sent to tmux via Tslime
|
Switchboard | ||||
Latest | |||||
Past week | |||||
Past month |
NEWS CONTENTS
- 20200730 : ports tree ( Jul 30, 2020 , opensource.com )
- 20190622 : Using SSH and Tmux for screen sharing Enable by Seth Kenlon Tmux ( Jun 22, 2019 , www.redhat.com )
- 20180918 : Getting started with Tmux ( Sep 15, 2018 , linuxize.com )
- 20100628 : TMUX – The Terminal Multiplexer (Part 1) by Cody ( Jun 28, 2010 )
- 20100628 : TMUX – The Terminal Multiplexer (Part 2) by Cody ( July 2, 2010 ,Hawk Host Blog )
- 20100628 : Rebinding the Action Key ( )
- 20100628 : Binding a key for "last-window" ( )
- 20100628 : Rebinding the pane splitting bindings ( )
- 20100628 : Modifying tab color & looks ( )
- 20100628 : Adding information to your session ( )
- 20100628 : Using shell scripting to setup your tmux enviroment ( )
- 20100628 : Notify you when a window has activity ( )
- 20100628 : Automatic window rename ( )
- 20100628 : tmux, a BSD alternative to GNU Screen ( Niall's Weblog )
- 20100628 : S ( Linux~ized )
- 20100329 : tmux: a replacement for gnu screen (updated) ( March 29, 2010 )
Old News ;-)
[Jul 30, 2020] ports tree
Jul 30, 2020 | opensource.com
. On Mac, use Homebrew .
For example, on RHEL or Fedora:
$ sudo dnf install tmuxStart tmuxTo start tmux, open a terminal and type:
$ tmuxWhen you do this, the obvious result is that tmux launches a new shell in the same window with a status bar along the bottom. There's more going on, though, and you can see it with this little experiment. First, do something in your current terminal to help you tell it apart from another empty terminal:
$ echo hello
helloNow press Ctrl+B followed by C on your keyboard. It might look like your work has vanished, but actually, you've created what tmux calls a window (which can be, admittedly, confusing because you probably also call the terminal you launched a window ). Thanks to tmux, you actually have two windows open, both of which you can see listed in the status bar at the bottom of tmux. You can navigate between these two windows by index number. For instance, press Ctrl+B followed by 0 to go to the initial window:
$ echo hello
helloPress Ctrl+B followed by 1 to go to the first new window you created.
You can also "walk" through your open windows using Ctrl+B and N (for Next) or P (for Previous).
The tmux trigger and commands More Linux resourcesThe keyboard shortcut Ctrl+B is the tmux trigger. When you press it in a tmux session, it alerts tmux to "listen" for the next key or key combination that follows. All tmux shortcuts, therefore, are prefixed with Ctrl+B .
- Linux commands cheat sheet
- Advanced Linux commands cheat sheet
- Free online course: RHEL Technical Overview
- Linux networking cheat sheet
- SELinux cheat sheet
- Linux common commands cheat sheet
- What are Linux containers?
- Our latest Linux articles
You can also access a tmux command line and type tmux commands by name. For example, to create a new window the hard way, you can press Ctrl+B followed by : to enter the tmux command line. Type
Splitting windows into panesnew-window
and press Enter to create a new window. This does exactly the same thing as pressing Ctrl+B then C .Once you have created more than one window in tmux, it's often useful to see them all in one window. You can split a window horizontally (meaning the split is horizontal, placing one window in a North position and another in a South position) or vertically (with windows located in West and East positions).
- To create a horizontal split, press Ctrl+B followed by " (that's a double-quote).
- To create a vertical split, press Ctrl+B followed by % (percent).
You can split windows that have been split, so the layout is up to you and the number of lines in your terminal.
tmux_golden-ratio.jpg(Seth Kenlon, CC BY-SA 4.0 )
Sometimes things can get out of hand. You can adjust a terminal full of haphazardly split panes using these quick presets:
Switching between panes
- Ctrl+B Alt+1 : Even horizontal splits
- Ctrl+B Alt+2 : Even vertical splits
- Ctrl+B Alt+3 : Horizontal span for the main pane, vertical splits for lesser panes
- Ctrl+B Alt+3 : Vertical span for the main pane, horizontal splits for lesser panes
- Ctrl+B Alt+5 : Tiled layout
To get from one pane to another, press Ctrl+B followed by O (as in other ). The border around the pane changes color based on your position, and your terminal cursor changes to its active state. This method "walks" through panes in order of creation.
Alternatively, you can use your arrow keys to navigate to a pane according to your layout. For example, if you've got two open panes divided by a horizontal split, you can press Ctrl+B followed by the Up arrow to switch from the lower pane to the top pane. Likewise, Ctrl+B followed by the Down arrow switches from the upper pane to the lower one.
Running a command on multiple hosts with tmuxNow that you know how to open many windows and divide them into convenient panes, you know nearly everything you need to know to run one command on multiple hosts at once. Assuming you have a layout you're happy with and each pane is connected to a separate host, you can synchronize the panes such that the input you type on your keyboard is mirrored in all panes.
To synchronize panes, access the tmux command line with Ctrl+B followed by : , and then type
setw synchronize-panes
.Now anything you type on your keyboard appears in each pane, and each pane responds accordingly.
Download our cheat sheetIt's relatively easy to remember Ctrl+B to invoke tmux features, but the keys that follow can be difficult to remember at first. All built-in tmux keyboard shortcuts are available by pressing Ctrl+B followed by ? (exit the help screen with Q ). However, the help screen can be a little overwhelming for all its options, none of which are organized by task or topic. To help you remember the basic features of tmux, as well as many advanced functions not covered in this article, we've developed a tmux cheatsheet . It's free to download, so get your copy today.
Download our tmux cheat sheet today! How tmux sparks joy in your Linux terminal Organize your terminal like Marie Kondo with tmux. S. Hayes Use tmux to create the console of your dreams You can do a lot with tmux, especially when you add tmuxinator to the mix. Check them out in the fifteenth in our series on 20 ways to be more productive with open source in 2020. Kevin Sonney (Correspondent) Customizing my Linux terminal with tmux and Git Set up your console so you always know where you are and what to do next. Moshe Zadka (Correspondent) Topics Linux
[Jun 22, 2019] Using SSH and Tmux for screen sharing Enable by Seth Kenlon Tmux
Jun 22, 2019 | www.redhat.com
Tmux is a screen multiplexer, meaning that it provides your terminal with virtual terminals, allowing you to switch from one virtual session to another. Modern terminal emulators feature a tabbed UI, making the use of Tmux seem redundant, but Tmux has a few peculiar features that still prove difficult to match without it.
First of all, you can launch Tmux on a remote machine, start a process running, detach from Tmux, and then log out. In a normal terminal, logging out would end the processes you started. Since those processes were started in Tmux, they persist even after you leave.
Secondly, Tmux can "mirror" its session on multiple screens. If two users log into the same Tmux session, then they both see the same output on their screens in real time.
Tmux is a lightweight, simple, and effective solution in cases where you're training someone remotely, debugging a command that isn't working for them, reviewing text, monitoring services or processes, or just avoiding the ten minutes it sometimes takes to read commands aloud over a phone clearly enough that your user is able to accurately type them.
To try this option out, you must have two computers. Assume one computer is owned by Alice, and the other by Bob. Alice remotely logs into Bob's PC and launches a Tmux session:
alice$ ssh bob.local alice$ tmuxOn his PC, Bob starts Tmux, attaching to the same session:
bob$ tmux attachWhen Alice types, Bob sees what she is typing, and when Bob types, Alice sees what he's typing.
It's a simple but effective trick that enables interactive live sessions between computer users, but it is entirely text-based.
CollaborationWith these two applications, you have access to some powerful methods of supporting users. You can use these tools to manage systems remotely, as training tools, or as support tools, and in every case, it sure beats wandering around the office looking for somebody's desk. Get familiar with SSH and Tmux, and start using them today.
[Sep 18, 2018] Getting started with Tmux
Sep 15, 2018 | linuxize.com
... ... ...
When Tmux is started it reads its configuration parameters from
~/.tmux.conf
if the file is present.Here is a sample
~/.tmux.conf~/.tmux.conf
configuration with customized status line and few additional options:# Improve colors set -g default-terminal 'screen-256color' # Set scrollback buffer to 10000 set -g history-limit 10000 # Customize the status line set -g status-fg green set -g status-bg blackCopy Basic Tmux UsageBelow are the most basic steps for getting started with Tmux:
Conclusion
- On the command prompt, type
tmux new -s my_session
,- Run the desired program.
- Use the key sequence
Ctrl-b
+d
to detach from the session.- Reattach to the Tmux session by typing
tmux attach-session -t my_session
.In this tutorial, you learned how to use Tmux. Now you can start creating multiple Tmux windows in a single session, split windows by creating new panes, navigate between windows, detach and resume sessions and personalize your Tmux instance using the
.tmux.conf
file.There's lots more to learn about Tmux at Tmux User's Manual page.
[Jun 28, 2010] TMUX – The Terminal Multiplexer (Part 1) by Cody
See also TMUX – The Terminal Multiplexer (Part 2) Hawk Host Blog
Jun 28, 2010
tmux is similar to screen as it lets you run numerous TTY's in the same terminal window. It supports some very cool and intuitive features natively as well as a much more readable configuration syntax (ever looked at a .screenrc file?).Why TMUX over Screen?
Well according to the FAQ for tmux it has the following advantages over screen:
- A clearly defined cilent/server model (windows are their own clients which allows flexibility on how you handle windows. You can attach and detach different windows in different sessions without any issues)
- Consistent, well-documented command interface. (You can use the same commands interactively as in the .tmux.conf file, more on that later)
- Easily scriptable
- Multiple paste buffers
- Vi & Emacs keybindings
- A more usable status line syntax (which also allows you to embed the output of a shell command, handy indeed.
Default keybindings & Functionality
The default keybindings for tmux are actually pretty intuitive, though if you're used to screen you'll likely get a little peeved with the default action binding of C-b, though this is easily changed to mimic screens behavior:
*NOTE* If you're like me the Ctrl-b binding isn't horribly intuitive especially if you're used to screen. You can rebind this by putting the following in ~/.tmux.conf:
set -g prefix Ctrl-a
- Ctrl-b c Create new window
- Ctrl-b d Detach current client
- Ctrl-b l Move to previously selected window
- Ctrl-b n Move to the next window
- Ctrl-b p Move to the previous window
- Ctrl-b & Kill the current window
- Ctrl-b , Rename the current window
- Ctrl-b % Split the current window into two panes
- Ctrl-b q Show pane numbers (used to switch between panes)
- Ctrl-b o Switch to the next pane
- Ctrl-b ? List all keybindings
Now these are pretty self explanatory – the real magic (for me) of tmux is the ease of modifying the default behavior to do what you want, but first things first: let's explore the default behavior of tmux.
Basic Window Handling
Start up tmux with the tmux command and you should be greeted with a simplistic terminal window that resembles screen – the only difference is it has a default status bar which is nice (easily added to screen as well).
Now let's create a couple of windows and go through them (we'll be using the default bindings). Hit Ctrl-b c a few times to create a few windows, you should notice that there are more tabs in the status bar.
Now if you're like me you like to have descriptive names of which each window is for, so let's rename them by hitting Ctrl-b ,. It should prompt you to rename the current window – type anything you want and hit enter. Now the current window is renamed to what you specified. Now going forward I'm going to have two windows open respectively named "window1" and "window2".
Once you rename your windows lets switch back and forth. We have several different ways of switching windows, so I'll go over the ones I personally use:
- Ctrl-b n (Move to the next window)
- Ctrl-b p (Move to the previous window)
- Ctrl-b l (Move to the previously selected window)
- Ctrl-b w (List all windows / window numbers)
- Ctrl-b <window number> (Move to the specified window number, the default bindings are from 0 – 9)
Now these ones fairly self explanatory however they don't really cater to a lot of different windows. What if you have 10+ windows open? It becomes quite tedious to find the window you want – but don't fret! Tmux has a find-window option & keybinding. Type Ctrl-b f and type in the window name you want (it actually searches for the window so you can type in only part of the name of the window you're looking for).
You can also get a list of the windows in the current session by executing the list-windows command. To execute commands interactively you type Ctrl-b : which will bring up a text prompt. From there you can execute any command tmux supports interactively (tab completion is supported).
Basic Pane Handling
One of the most powerful features tmux offers is the ability to split up your current window into "panes". Anyone whose familiar with tiling windows managers will feel quite at home. It's a bit difficult to explain this in words so a simple screenshot will suffice:
Now here are some basic key bindings and commands to split the terminal window (vertically and horizontally) and to switch between them
- Ctrl-b % (Split the window vertically)
- Ctrl-b : "split-window" (Split window horizontally)
- Ctrl-b o (Goto next pane)
- Ctrl-b q (Show pane numbers, when the numbers show up type the key to goto that pane)
- Ctrl-b { (Move the current pane left)
- Ctrl-b } (Move the current pane right)
Now some obviously the default bindings don't encompass some of features, such as splitting horizontally. I personally rebind the keys so "|" splits the current window vertically, and "-" splits it horizontally. Not the easiest things to type, though easy to remember.
You can achieve this by putting the following in ~/.tmux.conf or by typing it in the interactive prompt (Ctrl-b :). Keep in mind if you do the latter it will only be in effect for that session:
unbind %
bind | split-window -h
bind – split-window -vAdvanced Window Handling
Now that we went over the basics lets dive a little deeper into some "advanced" features of tmux. This includes moving windows around, linking windows together, switching windows from different sessions and much more. By default tmux doesn't have key bindings for these features, so we'll be entering them in the interactive dialog (accessed by typing Ctrl-b :) – keep in mind tmux is very scriptable and you can easily create your own key bindings for all of these.
Moving Windows
Now if you want to move a window you can use the move-window command. The command to do this:
move-window [ −d] [ −s src-window] [ −t dst-window]swap-window [ -d] [ -s src-window] [ -t dst-window]
Similar to the above command except both windows have to exist – if they both do the window with the ID source and destination windows will be swapped.
Advanced Pane Handling
When you split up a window into multiple smaller windows they're referred to as panes. Tmux also offers "layouts" for the panes, or the default positioning and behavior when you create a new window. You can switch through the panes by using the key binding Ctrl-b <space> which will toggle through the different layouts. Each one has different behaviors such as main-vertical which means the current active pane will take up more space in the current window, or even-vertical which will split the panes equally. Since this is difficult to describe in text I believe a few screen shots are in order:
Now that you've seen the different layouts let's see what we can do with these panes. As mentioned above in the "Pane Handling" section you can switch through panes by issuing the Ctrl-b o key combination (which is using the down-pane command) or by typing Ctrl-b q which will list the pane ID's and you select the one you want.
Make your pane into its own window
If you want to take a pane and make it into its own window you do the following:
Ctrl-b : "break-pane"
Simple enough, you should now have the pane in its brand new window. If you don't want it to automatically make the pane you just broke out as the active window issue the "-d" switch which will simply break the pane to a new window but keep you in the current window.
Resizing Panes
You can also resize panes if you don't like the layout defaults. I personally rarely need to do this, though it's handy to know how. Here is the basic syntax to resize panes:
Ctrl-b : resize-pane (By default it resizes the current pane down)
Ctrl-b : resize-pane -U (Resizes the current pane upward)
Ctrl-b : resize-pane -L (Resizes the current pane left)
Ctrl-b : resize-pane -R (Resizes the current pane right)
Ctrl-b : resize-pane 20 (Resizes the current pane down by 20 cells)
Ctrl-b : resize-pane -U 20 (Resizes the current pane upward by 20 cells)
Ctrl-b : resize-pane -L 20 (Resizes the current pane left by 20 cells)
Ctrl-b : resize-pane -R 20 (Resizes the current pane right by 20 cells)
Ctrl-b : resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
Ctrl-b : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)
… etcHopefully you get the jist – don't get confused! Simply load up a tmux session and split the window a couple of times and issue the above commands. It should become fairly evident how it behaves after fiddling with it for a bit.
Utilizing the client / server model
I've avoided mentioning that a lot of these commands can actually be applied to numerous tmux sessions which allows quite a bit of flexibility – the reason for avoiding it is it's too much information all at once! An example of using this functionality is if you have two sessions open you can "link" or "move" windows across different sessions – unfortunately the actual "how-to" will be in Part 2.
Conclusion
Tmux may be a bit confusing however it's worth putting in a few minutes to check it out and see what it has to offer – quick easy and intuitive.
Upcoming in Part 2
I'll be going over several tips and tricks for tmux including:
- Custom hotkeys
- Custom window styles & colors
- Scripting with tmux (bash, sh)
- How to use the server / client model further
TMUX – The Terminal Multiplexer (Part 2) by Cody
July 2, 2010 |Hawk Host Blog
Posted onIn part 1 I went over the basics of tmux and how to utilize its basic features. In this portion I'm going to dive a bit more into customizing tmux to make it easier and prettier to work with. I'll also give some examples on how to utilize the client/server model.
Since this part is less of a tutorial and more of a tips / reference I decided a table of contents based layout would be a bit easier to use:
Note: If you have any tips, tricks or pre-made configurations you want to contribute to this post please do so in the comments and I'll append them to this post.
Note**: You can type the commands into a live tmux session or place them in ~/.tmux.conf file which is automatically loaded when tmux is started.
Modify tmux bindings
- Rebinding the action key (Ctrl-b)
- Bind a key to switch between last active window
- Rebinding pane splitting bindings
Modify tmux looks & style
Misc tips & tricks
- Setting up your tmux environment via shell scripting
- Notify you when a window has activity
- Have tmux rename window automatically on command run
Modify tmux bindings
By default tmux has a decent default layout for hotkeys however there are a few keys that either made my fingers contort into ways they shouldn't have or keys I simply always forgot. Luckily tmux offers a very simple syntax to rebind any key.
Rebinding the Action Key
Here is how you can rebind the Ctrl-b prefix to be something a bit easier to type. I personally use Ctrl-a similar to screen:
set-option -g prefix C-a
Note: The "-g" switch stands for global so the binding will affect every window. Alternatively the set-option command accepts arguments to specify the session and target of that particular binding if you like.
Now every subsequent command will be prefixed with Ctrl-a instead of Ctrl-b.
Binding a key for "last-window"
One of my favorite screen hotkeys is the last window hotkey which allows you to quickly switch between the current window and last window that was active. By default tmux doesn't have a binding for this however it can easily be achieved by using the following:
bind-key C-a last-window
What this does is binds Ctrl-a to switch between the last active window. To use this binding you would hit Ctrl-a twice (since the prefix is set to Ctrl-a and the binding Ctrl-a).
Rebinding the pane splitting bindings
One of the most powerful features of tmux is the ability to natively split your windows into several panes. Unfortunately the default bindings to achieve this are simply unintuitive. As a result I've rebound the splitting commands to something I could remember:
unbind % # Remove default binding since we're replacing
bind | split-window -h
bind – split-window -vAt first this may look odd but for me it's easier to remember that "|" splits the screen vertically while "-" splits the screen horizontally. To achieve the below window structure you would type the following sequence:
Ctrl-a |
Ctrl-a –
Ctrl-a –The first Ctrl-a |command splits the current window in half. The active window is the pane on the right so the subsequent Ctrl-a – splits that window into two vertically. Hitting Ctrl-a – once more now splits that active window into two more by splitting it vertically.
Note: Depending on the active layout you're using the behavior of how the windows split may be different.
Modify tmux look & style
The default colors and style of tmux isn't awful however it's somewhat bland for my liking. I personally only have modified tmux slightly however it allows you to do quite a bit. In this section I'll go over some of tmux's style features.
Modifying tab color & looks
By default the tab colors are pretty bland and it makes it difficult to distinguish the active window from the other windows. Here is the default tmux tabs vs. the modified ones (snippet below):
As you can see the latter version is much more clear and uses some variable expansions tmux provides (hostname, etc). You can achieve this output with the following:
# Set status bar
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green]#H'The first two commands set the background to black and the text to white. The third command is where the magic happens: the status-left command tells tmux to display the following text to the left of the terminal. The [fg=green]#H portion tells tmux to display the hostname of localhost and make it green. The #H portion is part of tmux variable expansion – please refer to the man pages for more information on other ones you can use.
That alone doesn't account for highlighting the active window. If you want to do that use the following snippet:
# Highlight active window
set-window-option -g window-status-current-bg redThe set-window-option -g window-status-current-bg red command tells tmux to change the background of the current active window to red. The set-window-option command has several other options you can pass to it to achieve similar affects.
Adding information to your session
Sometimes it might be useful to add some information from your local machine to the tmux screen. Earlier we played with the status-left command which sets the left portion of the status bar. Let's use the status-right command to add some information to the right side:
As you can see I've added the amount of users logged in and the current load average for my computer. This was achieved with the following snippet:
set -g status-right '#[fg=yellow]#(uptime | cut -d "," -f 2-)'
Similar to before the #[fg=yellow] portion tells tmux to make the font yellow. The #(uptime | cut -d "," -f 2-) portion tells tmux to run that cmd and output it on the right of the status bar.
Note: If you're not familiar with shell scripting this command is very simple. It runs the uptime command and then passes it to the cut command which splits it at the commas (,). The -f 2- portion says to print out everything from the second comma onward.
Note**: By default the status bar is redrawn every 15 seconds however you can modify this by setting the status-interval command.
Misc tips & tricks
Using shell scripting to setup your tmux enviroment
Tmux allows you to easily run commands for your different sessions through the command line without having to ever login to the session. This also allows us to make a simple bootstrap script which will setup your tmux environment and log you into it. Here is an example script I personally use:
?
01 02
0304
0506
0708
0910
11#!/bin/sh
tmux new-session -d -s hawkhost
tmux new-window -t hawkhost:1 -n
'Server1'
'ssh [email protected]'
tmux new-window -t hawkhost:2 -n
'Server2'
'ssh [email protected]'
tmux new-window -t hawkhost:3 -n
'Server3'
'ssh [email protected]'
tmux new-window -t hawkhost:4 -n
'Server4'
'ssh [email protected]'
tmux new-window -t hawkhost:5 -n
'Server5'
'ssh [email protected]'
tmux
select
-window -t hawkhost:1
tmux -2 attach-session -t hawkhost
The command new-session -d -s hawkhost creates a new tmux session, detaches it (so it doesn't open in your current terminal) and names it hawkhost in this case.
The following set of new-window commands create five new windows and executes the command at the end. The arguments are broken down as follows: -t hawkhost :1 tells tmux to "target" the session hawkhost and the window with the id of 1. The -n 'Server1' 'ssh [email protected]' portion tells tmux to name the window Server1 and execute the ssh [email protected] command in it.
The last two commands are pretty straight forward. The select-window -t hawkhost:1 command tells tmux that you want the active window the session to be hawkhost and window 1. The -2 attach-session -t hawkhost tells tmux you want to attach the terminal with 256 colors and attach to the session hawkhost.
Note: This is the command that brings the tmux session to the foreground. If you recall earlier when the script created the session we specified the -d switch which prevents it from loading in your terminal.
Notify you when a window has activity
This quick snippet will have tmux notify you in the status area when a window has activity:
# Set window notifications
setw -g monitor-activity on
set -g visual-activity onAs you can see in the first image it lets me know that there was activity in window 0 (in this case sleep 10 && echo "narwhal" and switching the window).
Automatic window rename
You can have tmux rename the window to the command that is currently running. This is useful when you load up something such as irssi and the window is labeled accordingly:
# Automatically set window title
setw -g automatic-rename
tmux, a BSD alternative to GNU Screen
Niall's Weblog
I started using tmux today. Its a terminal multiplexer / task switcher for UNIX-likes, very much in the same vein as GNU Screen. However, its a from-scratch implementation, designed to be clean, sane and easy to configure. The more liberal 3-clause BSD license is a plus also, since it means that OpenBSD has been able to integrate it into the source tree, so that its available out of the box.Comparison with GNU Screen
I've been a heavy screen user for many years – almost all my work is done on remote screen sessions. However, screen configuration has always been essentially black magic to me. For this reason, tmux and its nice manual page is a breath of fresh air. `tmux list-commands' is very straight forward and easy to grok. Furthermore, I like that everything in tmux is scriptable from the command line – you can run commands like `tmux resize-pane-up -t comms' to resize the pane on a session called 'comms'.
The other thing I really like about tmux is its default status bar. Some people might hate this, but I find it very useful to have a clock and a list of windows along with the process executing in them. This took quite some work to set up to my liking in GNU screen, but the default in tmux is great.
Switching from gnu screen to tmux (updated)
Linux~ized
# ` is an interesting key for a prefix
set-option -g prefix `
# set-option -g prefix C-aunbind-key C-b
bind-key C-a last-window
bind-key ` last-window
bind-key a send-prefix# we might need ` at some point, allow switching
# we can also send the prefix char with `-a
bind-key F11 set-option -g prefix C-a
bind-key F12 set-option -g prefix `# 0 is too far from `
set -g base-index 1# set-option -g default-terminal "screen-256color"
set-option -g mouse-select-pane on
set-option -g status-keys vi
set-option -g bell-action any
set-option -g set-titles on
set-option -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name,active (or not)
set-option -g visual-bell onsetw -g mode-keys vi
setw -g mode-mouse on
setw -g monitor-activity onbind e previous-window
bind f next-window
bind j up-pane
bind k down-paneset-option -g status-utf8 on
# set-option -g status-justify centre
set-option -g status-justify left
set-option -g status-bg black
set-option -g status-fg white
set-option -g status-left-length 40set-option -g pane-active-border-fg green
set-option -g pane-active-border-bg black
set-option -g pane-border-fg white
set-option -g pane-border-bg blackset-option -g message-fg black
set-option -g message-bg green#setw -g mode-bg black
setw -g window-status-bg black
setw -g window-status-current-fg green
setw -g window-status-alert-attr default
setw -g window-status-alert-fg yellowset -g status-left '#[fg=red]#H#[fg=green]:#[fg=white]#S #[fg=green]][#[default]'
# set -g status-right '#[fg=green]][#[fg=white] #T #[fg=green]][ #[fg=blue]%Y-%m-%d #[fg=white]%H:%M#[default]'
set -g status-right '#[fg=green]][ #[fg=blue]%Y-%m-%d #[fg=white]%H:%M#[default]'set -g history-limit 4096
# `+r reloads the configuration, handy
bind r source-file ~/.tmux.conf
[Mar 29, 2010] tmux: a replacement for gnu screen (updated)
March 29, 2010
I have recently discovered tmux, a replacement for the slightly aging gnu screen. The so called "terminal multiplexer" allows to open several terminals inside the same terminal window. Much like gnu screen, you can split the screen, resize the different parts etc. However, tmux allow the usage of 256 color terminals and is based upon a client server infrastructure. And before you ask, like screen, it will stay alive and run your favorite app until you reconnect to the session.
It is part of the OpenBSD base distribution but will compile and run on a number of OS including Linux. Solaris, AIX, etc.
Update: for Mac OS users, it is available from macports.
Recommended Links
Google matched content |
Softpanorama Recommended
Top articles
Sites
tmux - Wikipedia
tmux - ArchWiki
Tmux Cheat Sheet & Quick Reference
Reference
Etc
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: July, 31, 2020