TMXから始めるためのやさしいガイド


あなたはおそらくあなたのコマンドラインのスキルをレベルをお探しですので、ここで終わった.そして、それは素晴らしいです、私は私がこのブログ柱を書いている全く同じ理由です.私はプログラムの方法を学び始めたので、私はターミナルの住人でした.私は、私が私のシェルにログインするとき、常に感じます.今日、私たちの端末の経験はさらに良い感じでしょう.我々は偉大なツールTMUXと呼ばれる私たちの知識とツールベルトをレベルアップします.

写真でDavid Iskander on Unsplash

What is tmux?

tmux is a terminal multiplexer, meaning it is a window manager within your terminal. It allows you to open multiple windows (sessions) within one terminal window (session). So it enables other programs to run from it, allowing you to manipulate them easily. Most of the folks find that one of the features to use tmux on a daily basis.

But, besides being a window manager, tmux can also do the following: Protect running programs on a remote server from connection drops by running them inside tmux. We’ve all been there - you connect to a server, you go to get your coffee/lunch, you come back, and the session is frozen or unresponsive. Allow a user to access programs running on a remote server from multiple different local computers.

Today, we are going to focus on the window manager aspect of tmux. In a future blog post, we will cover some advanced usages of tmux and how it can benefit you.


Installing

You can install tmux using package managers on all major platforms, but let’s cover some of the most famous ones. On Debian or Ubuntu, you can do the following:

apt install tmux

On Mac OS, you can use brew:

brew install tmux

To check whether you succeeded in the installation, let’s try to read man pages for tmux with:

man tmux

If you get something like this:

tmux Manual TMUXマニュアル
行くのはよい.

Starting tmux

We can start tmux by using the tmux command in our terminal to see what its all about. After that, you can see that everything stayed the same, except the green line at the bottom. What happened here is that we connected to a tmux server as a client. tmux runs a server on a specific PID in the background, and when we type tmux we run the server automatically.

So we are connected to the tmux server from a session named 0, as you can see in the [0] portion of the screen. So tmux acts as sort of a layover of the standard terminal session. Let’s have a look at what you get when you enter a tmux session:

TMUXセッションの開始
左下にある[ 0 ]を見ます.右隣に0:zsh どのウィンドウが開いているか、どのプログラムが実行されているかを示す.私たちはちょうどこのセッションを始めました.
あなたは通常、それを使用するようにターミナルを使用して行くことができるが、それは単なる退屈な、右でしょうか?TMUXで初心者としてできること、2つを学びましょう.TMUXでのペインを通じて制作・移動する過程を経験したい.

Pane Management

If you’ve used iTerm2 and utilized pane splitting there, you will like this feature a lot. It is pretty much the same in tmux, with the only difference being the shortcuts you use to create new panes. In iTerm2, you can do cmd + d and cmd + shift + d to split panes vertically and horizontally.


Creating Panes

In tmux, you can do it with Ctrl-b % for a vertical split and Ctrl-b " for a horizontal one. You will see that all shortcuts start with Ctrl-b or C-b for short. To make C-b shortcuts work, you need to press the control key and b key at the same time, then you can press the following character or a symbol like " to split horizontally. for example. C-b signals tmux that you are about to send a shortcut its way. Let’s try out this feature together below:

Tmuxでパンを分割する方法
あなたが何らかの理由でショートカットのファンでないならば、あなたはタイプすることができますtmux split-window -h 水平方向の分割を行うtmux split-window -v 垂直方向の分割を行う.

Moving Around the Panes

We might’ve pushed it too much in the GIF above, but you get the idea. Now, for the most important part - how to move around? Don’t worry, it’s easier by default than in iTerm2. You use C-b and arrows left, right, up, and down. So C-b Arrow-Left C-b Arrow-Right and so on.


Closing Panes

If you finish with one pane, just press Ctrl-d , and it will get closed.

Now let’s try to create a new window.


Window Management

A window in tmux is similar to a tab in iTerm2, pretty much. It’s a new canvas for you to split it into panes and run commands. You must be asking - how do I create one?


Creating Windows

Just do C-b c , and a new window will form. You can try it out a couple of times. I did a similar thing, except I opened a program in each window to see the difference together. Let’s have a look below:

TMUXの窓
TMUXステータス行で次のテキストを見ることができます.
0:zsh 1:vim* 2:ed- 3:ruby
The 0:zsh zshが動いている最初のウィンドウを示します.The 1:vim* 私たちは、第2のウィンドウでは、我々はvimを実行しているし、アスタリスクをすることはできません* それがアクティブなウィンドウです.The 2:ed- ダッシュを除く- それが最後の窓であることを我々に示してください.もう一つの質問は、現在それ自体を課します-どのように、我々はウインドウを変えますか?

Navigating Through Windows

No worries, I got you. You can change windows in multiple ways, but I find this one most effective. You can use the combination of C-b and index of a window, e.g. C-b 1 to go to the window marked as 1 in the tmux status line. So C-b 0 in our case will open the window with zsh open since it shows like 0:zsh in the tmux status line at the bottom of the screen.

You can also use C-b p for a previous window, C-b n for the next window, and C-b l for the last window (this is where that dash - comes to play from the section above).


tmux Sessions

tmux wouldn’t be great with its flexible session. You can attach and detach from a session anytime you want. Most of the folks praise tmux for its session management. Imagine sessions as different areas of work you do. For example, one session can relate to your private web project where you run frontend, backend, editor, tests, and so on. Another session can be an SSH session on some server where you are messing around with infrastructure.


Attaching and Detaching From Sessions

To feel the power of sessions, you can start tmux in another terminal window or a tab (assuming you have one session running from the examples above). If you now press C-b d you should see the following:

$ tmux
[detached (from session 1)]

Cool, we detached from the session we just created. Now in that same terminal window, type tmux ls :

$ tmux ls
0: 4 windows (created Thu Aug 12 20:08:22 2021) (attached)
1: 1 windows (created Thu Aug 12 20:15:03 2021)

The first session marked with 0 shows that we have four windows open, and we are attached to it. But the second session marked with 1 (one) is not attached. With the C-b d , we detached from the session marked with 1, and we used tmux ls to list all the available sessions. How neat, now we can organize our work even better.

If you don’t like the default naming of sessions with numbers like 0 and 1, you can always give your session a name by using tmux new -s heythere . Now the created session will get heythere name. We can see that by detaching ( C-b d ) and running tmux ls again:

$ tmux ls
0: 4 windows (created Thu Aug 12 20:08:22 2021) (attached)
1: 1 windows (created Thu Aug 12 20:15:03 2021)
heythere: 1 windows (created Thu Aug 12 20:21:09 2021)

We can then attach to the heythere session easily with:

tmux attach -t heythere

And we’re back in the heythere session. Pretty cool, right? I think that’s enough for one. We got a lot to process and use in our terminal. I decide we gather back and try to use this for a couple of days or weeks.


Final Thoughts

And that should be it for getting started with tmux. I want to mention one thing that might help you and me out until the next blog post. If you ever get lost or forget about shortcuts, there’s C-b ? shortcut that shows a list of commands you can use. Here’s how it looks:

tmuxヘルプ画面
また、あなたがTimm 2を使っているならば、チェックするもう一つの大きなものは、TMUXとのその統合です.もっと読むiTerm2 docs .
私はTMUXのいくつかの高度な使用でフォローアップのブログ記事を書く予定です.あなたがこの1つが好きで、もう一つのブログ柱を見たいならば、参加してくださいnewsletter , それはあなたがそれが出ているときに通知を取得します.
いつものように、お友達や同僚と共有することを忘れないでください.以下のようなメッセージがあります.
参加してくれてありがとうございます.次の方にお会いできるのを楽しみにしています.
チアーズ.