tmux tips
In this post I would like to show you the tmux cli tool. tmux is a terminal multiplexer allowing you to run your cli task in the background and use multiple terminals at once (hence the name multiplexer).
I will show you the value of tmux by showing a couple of usecases. But before we start you need to know how to invoke tmux commands.
how to open tmux
First you need to open tmux which is as easy (assuming you installed it with e.g.) as typing
tmux
how to invoke tmux commands
tmux command is preceded by keyboard shortcut ctrl+b (which BTW can by changed) and then action itself.
E.g. to detach from tmux you need to invoke
ctrl+b d
so you press ctrl, then (still holding ctrl) b, then release them both and finally press d (in general plus sign in notation means you hold keys together while space means you unhold previous sequence)
Run task in the background
In this scenerio we will open tmux, run some task, then detach from it and attach again, kill command and finally exit for good.
- open tmux in your console app
tmux
- run task
Let's ping some host every 10 seconds
BTW you can open pajacyk.pl and click clown's belly. Every (human) click is a charity support.
ping pajacyk.pl -i 10
- Leave tmux while ping is still going on
Pressing
ctrl+b d
will make ping command still run in the background
- Re-attach to tmux instance
Now the nices part you can even log out from the host running tmux (like close connection via ssh). After you log in again, just invoke
tmux attach
or shorter
tmux a
Now you are back in tmux, and you should see ping results going on.
Let's kill ping by ctrl+c
Assuming you really finished your job you can leave tmux for good. To exit just press type
exit
or press
ctrl + d
Split tmux window horizontally and verticaly to have two terminal visible at once
To split window horizontally type
ctrl+b "
when splitting verticaly do
ctrl+b %
Now to move between splitted windows use
ctrl+b [left/right/up/down arrow]
Let's assume you want to zoom in into one specific window:
ctrl+b z
Use the same command to unzoom.
One more thing...
Another cool gadged is to display clock in the current window
ctrl+b t