tmux 시작을 위한 부드러운 가이드
David Iskander에 Unsplash의 사진
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.
설치 중
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 수동가셔도 좋습니다.
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:
왼쪽 하단에 세션을 나타내는 [0]이 표시됩니다. 바로 옆에는 어떤 창이 열려 있고 어떤 프로그램이 실행되고 있는지 보여주는
0:zsh
가 있습니다. 방금 이 세션을 시작했기 때문에 하나의 창만 열려 있고 zsh가 거기에서 실행 중입니다.계속해서 평소처럼 터미널을 사용할 수 있지만, 그것은 그저 지루할 것입니다. 그렇죠? tmux 초보자로서 할 수 있는 것 한두 가지를 배워봅시다. tmux에서 창을 만들고 이동하는 과정을 살펴보고 싶습니다.
창 관리
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.
창 만들기
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 split-window -h
를 입력하여 수평 분할을 수행하고 tmux split-window -v
를 입력하여 수직 분할을 수행할 수 있습니다.창 주변 이동
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.
창 닫기
If you finish with one pane, just press Ctrl-d
, and it will get closed.
Now let’s try to create a new window.
창 관리
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?
창 만들기
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 상태 표시줄에서 다음 텍스트를 볼 수 있습니다.
0:zsh 1:vim* 2:ed- 3:ruby
0:zsh
는 zsh만 실행되는 첫 번째 창을 나타냅니다. 1:vim*
두 번째 창에서 Vim이 실행되고 있다는 것을 알 수 없으며 별표*
가 활성 창임을 보여줍니다. 2:ed-
는 대시-
가 마지막 창임을 보여 주는 것을 제외하고는 동일합니다. 또 다른 질문이 지금 스스로에게 부과됩니다. 창을 어떻게 변경합니까?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 세션
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.
세션에서 연결 및 분리
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.
마지막 생각들
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:
또한 iTerm2를 사용 중인지 확인해야 할 또 다른 좋은 점은 tmux와의 통합입니다. 자세한 내용은 iTerm2 docs .
tmux의 고급 사용법에 대한 후속 블로그 게시물을 작성할 계획입니다. 이 게시물이 마음에 들었고 다른 블로그 게시물을 보고 싶다면 newsletter 가입을 고려하세요. 게시물이 나오면 알림을 받을 것입니다.
항상 그렇듯이 친구나 동료와 공유하는 것을 잊지 마십시오. 다음은 좋아요, 리트윗, 무시 또는 원하는 대로 메시지를 보낼 수 있는 트윗입니다.
참여해주셔서 감사합니다. 다음 회에서 뵙기를 기대합니다.
건배.
Reference
이 문제에 관하여(tmux 시작을 위한 부드러운 가이드), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/nikolalsvk/gentle-guide-to-get-started-with-tmux-3fhc텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)