Many data scientists get stuck with the manifold of tools available to them. In this article, I will present the Tmux tool. What it does best is turn a single terminal into a multi-pane tool, where you can take care of more than one task at a time.
Table of Contents
- Start Session
- Split Panes
- Navigate through the Panes
- Close/Open Tmux Session
- List and Kill Sessions
- Most important commands inside a Tmux Session
- Useful Resources
Tmux allows you to create multiple tabs and panes within a single terminal window. It can also keep programs running after you disconnect (e.g. when you ssh into an AWS instance).Tmux lets you run programs on your server, close your terminal,come back later and your program will still be running in the exact same way.
The best way to install Tmux on Mac is via HomeBrew by running the following command in the terminal:
brew install tmux
or for Ubuntu and derivatives:
sudo apt-get install tmux
After downloaded, check if it has been properly installed by running the following command which will print out its version:
First, you need to know a few terms before running Tmux.
- Magic Command: This is the key combination that must be entered before entering any shortcut key. The default magic command for tmux is
ctrl + b.
- Session - Saved collection of windows and panes and programs you left running inside
- Attaching - Enter a running session
- Detaching - Exit a running session (without killing it)
- Window - Similar to a tab in your browser. Only one window is visible at a time.
- Pane - Belongs to a window. You can have many of these visible at once.
Start a session by simply running the following command on a terminal:
it looks like nothing happened, except from a little green bar at the bottom.
Start a new with session name:
tmux new -s myname
Once inside the tmux session, you can split the window vertically:
ctrl + b and "
or horizontally (right/left)
ctrl + b and %
My favorite splitted type is:
- First split vertically
- Then split horizontally
As displayed in the image above I use the down right window to run my Jupyter notebook and the other to run commands.
Navigate through the Panes
You can navigate through the panes by running:
ctrl + b and the arrow key
- ctrl+b+↓: move to the down window
- ctrl+b+→: move to the right window
Close/Open Tmux Session
You can close Tmux (detach) by simply running:
ctrl + b and d
Tmux will continue running in the background. This is really useful as any notebooks, the kernels I had running, they are all still sitting there. You can return back to an existing session by typing the following command on the terminal:
tmux a -t myname #by name tmux a 4 #by number (in this case 4)
tmux a # (or at, or attach)
If you want to exit Tmux and force it to stop running this session instead of using
ctrl+b and d use instead:
ctrl + b and &
🚀 For people who like video courses and want to kick-start a career in data science today, I highly recommend the below video course from Udacity:
📚 While for book lovers:
- "Python for Data Analysis" by Wes McKinney, best known for creating the Pandas project.
- "Hands-on Machine Learning with Scikit-Learn, Keras, and TensorFlow" by Aurelien Geron, currently ranking first in the best sellers Books in AI & Machine Learning on Amazon.
- "Deep Learning" by Ian Goodfellow research scientist at OpenAI.
List and Kill Sessions
You can get a list of all sessions by running:
Kill a specific session:
tmux kill-session -t myname
Kill all sessions:
Usually those commands are running outside of a Tmux session (on your normal terminal without the little green bar at the bottom).
Most important commands inside a Tmux Session
Start each command with CTRL + b, release, then press one of the following inside a Tmux session:
% vertical split " horizontal split d detach from session (it keeps running in the background) x kill pane Up/Down/Left/Right move between panes : + resize-pane -D Resizes the current pane down : + resize-pane -U Resizes the current pane upward : + resize-pane -L Resizes the current pane left : + resize-pane -R Resizes the current pane right : + resize-pane -D 20 Resizes the current pane down by 20 cells
Some useful resources can be found below:
This brings us to the end of this article. Hope you got a basic understanding of how you can use Tmux.
If you liked this article, please consider subscribing to my blog. That way I get to know that my work is valuable to you and also notify you for future articles.
Thanks for reading and I am looking forward to hear your questions :)
Stay tuned and Happy Machine Learning.