DevEnv

Tmux - 터미널 작업 효율을 올리자

쌍쌍바나나 2017. 11. 2. 22:56
반응형

들어가며

tmux 설치부터 환경 설정, 단축키, 설치하면서 에러 모든 내용이 담겨져 있다. 기능을 한번에 전부 다 사용할 수 없겠지만, 꾸준히 보면서 하나씩 추가하면서 사용하면 정말 나중에 업무 효율이 올라갈 것이다.

일단 설치를 해야하는 이유는

1.내가 작업하는 터미널이 종료되어도 그대로 세션(session)이 유지되기 때문 2.서버에서 작업할때, timeout이 되면? 좌절, 그대로 세션 유지 3.여러개의 window, pane을 사용하기 때문에 그냥 일단 써보셔요

https://tmux.github.io/ tmux is a terminal multiplexer What is a terminal multiplexer?

It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more. See the manual.

tmux vs screen

  • 명확한 클라이언트/서버 모델 (각 윈도우는 유연한 클라이언트로 다른 세션에 자유롭게 attach/detach)
  • 문서가 잘 되어있고 일관된 명령어(설정파일인 .tmux.conf에서도 동일한 명령어를 사용).
  • 스크립트를 구현
  • 다중 붙혀넣기 버퍼
  • Vi와 Emacs 키바인딩을 지원
  • 상태바에 대한 지원

tmux 구성

  • session : tmux 실행 단위. 여러개의 window로 구성.
  • window : 터미널 화면. 세션 내에서 탭처럼 사용할 수 있음.
  • pane : 하나의 window 내에서 화면 분할.
  • status bar : 화면 아래 표시되는 상태 막대.

최신 버전의 tmux를 설치

If you use Debian/Ubuntu, you can just run apt-get install tmux, and voila.

Since the title was about centos 7, then do the following step to install tmux.

(1). tmux has a library dependency on libevent which, of course, isn’t installed by default. $ wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz $ tar xzvf libevent-2.0.21-stable.tar.gz $ cd libevent-2.0.21-stable $ ./configure && make $ sudo make install (2). To get and build the latest from version control: https://github.com/tmux/tmux/tree/2.3

$ git clone https://github.com/tmux/tmux.git
$ cd tmux
$ sh autogen.sh
$ ./configure && make

cd deploy git clone https://github.com/tmux/tmux.git cd tmux sh autogen.sh ./configure && make echo export TMUX_HOME=/home/jslee/tmux >> ~/.bashrc echo export PATH=$PATH:${TMUX_HOME} >> ~/.bashrc

Tips:

(1). During the second step, if you encounter with "libevent not found” error" You should install the libevent development package, by running the following command. $ yum install libevent-devel

(2). If you run with "curses not found" error To compile the code you need the devel packages, run the following comamnd $ yum install ncurses-devel $ yum install glibc-static

https://gist.github.com/Root-shady/d48d5282651634f464af

protocol version mismatch (client 8, server 7)

  • 현재 실행중인 tmux를 종료하자
    • $ pkill tmux
    • https://unix.stackexchange.com/questions/122238/protocol-version-mismatch-client-8-server-6-when-trying-to-upgrade

tmux 명령어

  • tmux show-buffers
  • tmux save-buffer foo.txt https://awhan.wordpress.com/2010/06/20/copy-paste-in-tmux/

[참고] * https://github.com/tmux-plugins/tpm * https://github.com/coeuvre/dotfiles/blob/master/tmux.conf * https://gist.github.com/Root-shady/d48d5282651634f464af

tmux.conf

  • https://github.com/tmux-plugins/tmux-yank (각 os에 맞는 clipboard를 설치)

export TMUX_HOME=/home/jslee/tmux >> ~/.bashrc export PATH=$PATH:${TMUX_HOME} ~/.bashrc source ~/.bashrc * tmux plugin 설치 * git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

  • tmux.conf는 아래와 같다

단축키

  • prefix Ctrl + b
  • gnu screen에서는 ctrl + a (변경이 가능)

  • Session

    • 생성
    • $ tmux new -s
    • 이름 수정
    • ctrl + b, $
    • 종료
    • $ (tmux에서) exit
    • 중단(detached)
    • ctrl + b, d
    • 세션 목록 보기 (list-session)
    • $ tmux ls
    • 세션 다시 시작
    • $ tmux attach -t

session은 클라이언트/서버 모델을 가지고 있기 때문에 세션은 터미널이 종료되어도 남아있음. 만약 해당 터미널을 예기치 못하게 종료가 되면, 그냥 다른 터미널을 키고 tums ls를 한 뒤에 session을 attach detach

  • Window
    • 생성
    • ctrl + b, c
    • 이름 수정
    • ctrl + b, ,
    • 종료
    • ctrl + b, &
    • ctrl + d
    • 이동
    • ctrl + b, 0-9 : window number
    • n : next window
    • p : prev windo w
    • l : last window
    • w : window selector
    • f : find by name
  • Pane

    • 나누기
    • ctrl + b, % : 횡 분할
    • " : 종 분할
    • 이동
    • ctrl + b, q 그리고 화면에 나오는 숫자키
    • ctrl + b, o : 순서대로 이동
    • ctrl + b, arrow : 방향키
    • 삭제
    • ctrl + b, x
    • ctrl + d
    • 사이즈 조절
      • (ctrl + b, :)
      • resize-pane -L 10 (-R, -D, -U)
  • [참고]

    • http://blog.hawkhost.com/2010/06/28/tmux-the-terminal-multiplexer/
    • http://blog.hawkhost.com/2010/07/02/tmux-%E2%80%93-the-terminal-multiplexer-part-2/
    • https://tmux.github.io/
    • http://man.openbsd.org/OpenBSD-current/man1/tmux.1
반응형