Slide 1

Slide 1 text

당신의 터미널을 윤택하게 해줄 비묀 레시피 Jongwook Choi

Slide 2

Slide 2 text

Hello Linux !? you@server ~ $ cowsay "How are you doing with your Linux?" ____________________________________ < How are you doing with your Linux? > ------------------------------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || 2 / 93

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

이 폭탄을 해제하려면 올바른 tar 명령어를 입력하세요. 기회는 단 한번 구관링 ㄴㄴ. 10초! http://xkcd.com/1168/ Yes, unix is hard.

Slide 5

Slide 5 text

Recipes Let's be much more productive!

Slide 6

Slide 6 text

생각했던 제목 후보들 터미널 삶을 편하게 해주는 마법의 레시피 생산성 부스팅 스팀팩 여러분의 손을 편안하게 해줄게요 리눅스 안쓸수 없다면 잘쐁시다 아직도 bash 쓰니? 저거 vim 맞어? 6 / 93

Slide 7

Slide 7 text

당신의 터미널을 윤택하게 해줄 7가지 레시피

Slide 8

Slide 8 text

저는 윈도우 쓰는데요 그러니 안들을래요 8 / 93

Slide 9

Slide 9 text

저는 윈도우 쓰는데요 그러니 안들을래요 안됩니다. 9 / 93

Slide 10

Slide 10 text

왜 이런걸 알아야 하는가? 1. 우리들은 서버 작업을 피할 수가 없습니다. 2. 로컬 머신이 아닌 Command-Line 작업환경도 개선할 수 있습니다. 3. UNIX가 아닌 로컬 머신에도 터미널이 있으면 여러가지 도구들을 쓸 수 있습니다. 왜 윈도우는 curl 없나요 10 / 93

Slide 11

Slide 11 text

Covered Topics ZSH tmux, fasd, .. 여러가지 유용한 커맨드라인 도구들 vim plugins 설정 관리하는 방법 윈도우 유저를 위하여.. 11 / 93

Slide 12

Slide 12 text

Part 1: 쉘. 12 / 93

Slide 13

Slide 13 text

Recipe 1 단축키를 익힌다.

Slide 14

Slide 14 text

유용한 단축키들을 알아둡시다. http://ss64.com/bash/syntax-keyboard.html readline 단축키: bash, zsh, python, screen, ... 모든 곳 공통! 많이 알수록 좋긴 하지만 너무 많으므로 이것만은 꼭!!! Ctrl-A/E : 줄의 맨 앞으로 Home / 맨 끝으로 End Ctrl-U : (kill-a-line) 현재 커서부터 줄 앞까지 모두 지운다. Ctrl-W : (kill-a-word) 현재 커서 앞의 단어를 지운다. Alt-. : 방금 명령의 last argument 를 입력한다. Ctrl-R : 명령줄 히스토리 검색 14 / 93

Slide 15

Slide 15 text

Recipe 2 보기 좋은 쉘이 쓰기도 좋다.

Slide 16

Slide 16 text

당신의 터미널 쉘이 이렇게 생겼다면 바로 전에 친 명령어가 어딨더라.... 16 / 93

Slide 17

Slide 17 text

이렇게 바꿔보지 않겠습니까? 쉘 테마와 설정은 취향이니까 개인의 미적 감각을 존중합니다 17 / 93

Slide 18

Slide 18 text

Recipe 3 Use ZSH.

Slide 19

Slide 19 text

ZSH (The Z Shell) bash: 친숙한 우리의 기본 쉘 -- Bourne (Again) SHell zsh: The Z shell is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting. 19 / 93

Slide 20

Slide 20 text

왜 ZSH 를 써야 하나요? 그동안 Bash로도 잘만 살아왔는데요... 20 / 93

Slide 21

Slide 21 text

Zsh Showcase (1): Better autocomplete ls (sub or suffix pattern) kill java[tab] ssh [tab] 21 / 93

Slide 22

Slide 22 text

Zsh Showcase (2): Fuzzy string matching vim /u/i/c/4/vector[tab] 22 / 93

Slide 23

Slide 23 text

Zsh Showcase (3): Path Globbing ls /usr/include/**/algorithm ls **/*.conf ls src/**/*.java 23 / 93

Slide 24

Slide 24 text

왜 ZSH를 써야 합니까? 더 이상 설명이 必要韓紙? 똑똑한 autocomplete 및 interactive UI fuzzy string/pattern 매칭 Path globbing (e.g. **/*.java) 오타 자동교정 다행히도.. Bash 와 (거의 완벽한) 호환성 남들이 많이 써요: 시눀의 눀세! + Configuration Framework 24 / 93

Slide 25

Slide 25 text

Configuration Frameworks oh-my-zsh (http://ohmyz.sh/) prezto (https://github.com/sorin-ionescu/prezto) Customize at your own! References https://github.com/skwp/dotfiles https://dotfiles.wook.kr/zsh/ 25 / 93

Slide 26

Slide 26 text

Recipe 4 Use FASD (Z)

Slide 27

Slide 27 text

FASD: Command-line productivity booster 가장 최근(recently) 및 자주 접근한(directory) 디렉토리나 파일을 기억하 고 있다가 빠르게 접근할 수 있도록 해준다. 27 / 93

Slide 28

Slide 28 text

FASD: Setup 설치: fasd 셋업 및 쉘 설정 추가 fasd 바이너리 $PATH에 셋업 (/usr/local/bin, ~/.local/bin) shell 설정파일 (zshrc, bashrc) 에서 eval $(fasd --init auto) a, s, d, f, z 등의 alias command 를 rc file 에 추가. 아 어려워 그냥 매뉴얼눀로 따라하면 돼요 oh-my-zsh, prezto 에 플러그인으로 달려있어서 알아서 다 해줍 니다. 참고: https://dotfiles.wook.kr/zsh/zsh.d/fasd.zsh 28 / 93

Slide 29

Slide 29 text

FASD: Usages $ z {path} $ z {path}[tab] $ vim f,{pattern}[tab] 29 / 93

Slide 30

Slide 30 text

Part 2: 도구. 30 / 93

Slide 31

Slide 31 text

Unix philosophy Write programs that do one thing and do it well to work together to handle text streams, because that is a universal interface Example # Print the 30 most frequent IP addresses from access log cat access.log | awk -F'\t' '{print $1}' \ | sort | uniq -c | sort -nr | head -n30 31 / 93

Slide 32

Slide 32 text

Recipe 5 일삽질 하면서 알게된 유용한 도구들

Slide 33

Slide 33 text

Vim (something) | vim - Examples # 7월 1일 (시간별) 로그 다 보고 싶다. $ cat logs.2014-07-01*.log | vim - # svn diff는 colorized output이 안됨.. $ svn diff | vim - 33 / 93

Slide 34

Slide 34 text

SSH $ ssh -p12345 root@my-awesome-server [command] 이미 사용법 다 아실테지만... ~/.ssh/config Host * user root port 12345 ssh remote-server -t vim -t : terminal allocation e.g. for h in $(HOSTS); do ssh -t $h /etc/hosts; done 34 / 93

Slide 35

Slide 35 text

Grep grep cat LARGE-FILE | grep 'pattern' cat LARGE-FILE | grep -i 'Case-InSeNsItive' cat LARGE-FILE | grep -v 'exclude-this' fgrep (fixed pattern), egrep (extended regexp) 35 / 93

Slide 36

Slide 36 text

Grep 현재 디렉토리에서 패턴 찾기 $ grep -rn (pattern) . 36 / 93

Slide 37

Slide 37 text

Grep 37 / 93

Slide 38

Slide 38 text

Beyond Grep ack (http://beyondgrep.com) grep 보다 빠름. 인간이 관심없는 .git, .svn, .min.js, binary 등을 적절히 빼줌. --cpp, --java 등 filetype에 따른 소스코드 검색이 가능. $ ack (pattern) Want more? ag (https://github.com/ggreer/the_silver_searcher) pt (https://github.com/monochromegane/the_platinum_searcher) 38 / 93

Slide 39

Slide 39 text

39 / 93

Slide 40

Slide 40 text

awk 정말 다양한 기능이 가능하지만.. 보통 특정 column 추출할 때 많이 쐁니다. $ ps aux | awk '{print $2}' # -F : 구분자 설정 $ cat data.csv | awk -F'\t' '{print $2}' 40 / 93

Slide 41

Slide 41 text

JSON 다루기 Python 2.6+ $ cat data.json | python -mjson.tool jq : command-line JSON processor $ curl https://api.github.com/user 2>/dev/null | jq . { "documentation_url": "https://developer.github.com/v3", "message": "Requires authentication" } 41 / 93

Slide 42

Slide 42 text

curl A must-know for web developers. -X: (e.g. -XPOST, -XGET) -x: use proxy (e.g. -x localhost:80) -d: request body -v: verbose (show headers) Example: POST a JSON $ curl $API_URL -XPOST -v \ -H 'Content-Type: application/json' \ -d '{"items" : [1, 2, 3]}' 42 / 93

Slide 43

Slide 43 text

httpie curl replacement for humans. (pip install httpie) 43 / 93

Slide 44

Slide 44 text

base64 encode/decode Python $ echo '{"data":""}' | python -mbase64 -e eyJkYXRhIjoiIn0K $ echo 'eyJkYXRhIjoiIn0K' | python -mbase64 -d {"data":""} Base64 $ cat ssug.json | base64 > ssug.json.base64 $ cat ssug.json.base64 | base64 -d 44 / 93

Slide 45

Slide 45 text

url encode/decode $ cat access.log | awk '{print $7}' /hello%20world /%EC%95%88%EB%85%95 음... # put this on your .bashrc or .zshrc alias urldecode="ruby -ruri -e 'ARGF.each do |l| puts URI.decode(l.chomp) end'" alias urlencode="ruby -ruri -e 'ARGF.each do |l| puts URI.encode(l.chomp) end'" $ cat access.log | awk '{print $7}' | urldecode /hello world /안녕하세요 45 / 93

Slide 46

Slide 46 text

tmux or screen @see https://dotfiles.wook.kr/tmux.conf 46 / 93

Slide 47

Slide 47 text

그 외 xargs parallel : execute parallel jobs in shell q (command-line SQL for CSV data) ngrep (network grep) pv (pipe progress viewer) xmllint, xmlstarlet (command-line xml selector) Other References http://commandlinefu.com Seven command line tools for data science 47 / 93

Slide 48

Slide 48 text

도구: 설치법 builtin commands 패키지 매니저를 통해 설치 CentOS : yum install [blah] Ubuntu : apt-get install [blah] Mac OS X : brew install [blah] 48 / 93

Slide 49

Slide 49 text

도구: 설치법 builtin commands 패키지 매니저를 통해 설치 CentOS : yum install [blah] Ubuntu : apt-get install [blah] Mac OS X : brew install [blah] ... 보통 기본 repo에는 없는 경우가 많다. 써드파티 repository 를 추가해서 패키지 매니저로 설치한다. CentOS : rpmforge, rhel, epel Ubuntu : add-apt-repository ppa:git-core/ppa 아직까지는 괜찮다 49 / 93

Slide 50

Slide 50 text

도구: 설치법 그래도 없네? 바이너리 하나인 경우 (e.g. jq) 그냥 binary 를 /usr/local/bin 등에 복사한다. 컴파일 설치 !! 헬게이트의 시작 Node, Python, Ruby 기반의 툴들 npm, pip, gem 등으로 설치해야 한다. 시스템 전역에 설치가 곤란한 경우에는 nvm, virtualenv, rvm 등 으로 계정별 가상 환경을 만들고 신나게 깔면 된다. 이쯤되면 그냥 안 쓰고 싶다 50 / 93

Slide 51

Slide 51 text

Real-world examples 실시간 쿼리 모니터링 $ tailf profiling2.log | awk -F'\t' '{print $2}' | jq '.query' 51 / 93

Slide 52

Slide 52 text

Real-world examples access log: 가장 많이 접속한 30명 찾기 cat access.log | awk -F'\t' '{print $1}' \ | sort | uniq -c | sort -nr | head -n30 맵리듀스!? 52 / 93

Slide 53

Slide 53 text

참 쉽죠? 누구나 쉽게 할수 있어요! 이제 그만 할게요 53 / 93

Slide 54

Slide 54 text

Part 3: Vim. 54 / 93

Slide 55

Slide 55 text

55 / 93

Slide 56

Slide 56 text

56 / 93

Slide 57

Slide 57 text

Out-of-box experience is hell.... 57 / 93

Slide 58

Slide 58 text

How about this? 58 / 93

Slide 59

Slide 59 text

A minimal ~/.vimrc " ... set nocompatible set backspace=indent,eol,start " 더 가독성 있는 색깔.." set bg=dark " 줄 번호 보이기." set number " better suggestion" set wildmenu set wildmode=list:longest,full What's in your .vimrc file? vim-sensible 59 / 93

Slide 60

Slide 60 text

Recipe 6 Vim Plugin을 사용하자

Slide 61

Slide 61 text

Plugin 설치법. 61 / 93

Slide 62

Slide 62 text

Pathogen git clone https://github.com/tpope/vim-pathogen ~/.vim/bundle/vim-pathogen ~/.vimrc runtime bundle/vim-pathogen/autoload/pathogen.vim call pathogen#infect() 플러그인 설치: Easy!! $ cd ~/.vim/bundle $ git clone https://github.com/kien/ctrlp.vim $ ls ~/.vim/kien/ctrlp.vim 62 / 93

Slide 63

Slide 63 text

고수의 방법 vim 설정을 git repository로 관리하고 git submodule 로 등록 vundle, neobundle, vim-addon-manager, vim-plug 등과 같은 플러그인 매니저를 활용 63 / 93

Slide 64

Slide 64 text

NerdTree : A tree explorer vim-airline : Status, Tabline for vim. 64 / 93

Slide 65

Slide 65 text

CtrlP.vim : Fuzzy file, buffer, etc finder 65 / 93

Slide 66

Slide 66 text

vim-fugitive : The ultimate git client on vim. 66 / 93

Slide 67

Slide 67 text

http://vimawesome.com/ Awesome Vim Plugins across the universe. 67 / 93

Slide 68

Slide 68 text

Part 4: 세팅 68 / 93

Slide 69

Slide 69 text

좋은거 알겠는데.. 69 / 93

Slide 70

Slide 70 text

세팅

Slide 71

Slide 71 text

세팅

Slide 72

Slide 72 text

또 세팅

Slide 73

Slide 73 text

Looooooots of workstations..

Slide 74

Slide 74 text

Recipe 7 Dotfiles

Slide 75

Slide 75 text

모든 설정은 관리되어야 한다. 75 / 93

Slide 76

Slide 76 text

git clone to the rescue 새로운 머신이 있는가? $ git clone [email protected]:myusername/dotfiles ~/.dotfiles $ cd ~/.dotfiles && ./install.sh 설정 동기화가 필요한가? $ cd ~/.dotfiles && git pull 76 / 93

Slide 77

Slide 77 text

다른 사람들의 dotfiles https://dotfiles.github.io/ @github: https://github.com/search?q=dotfiles YADR: https://github.com/skwp/dotfiles mine: https://dotfiles.wook.kr 77 / 93

Slide 78

Slide 78 text

전 윈도우 유저인데요... 78 / 93

Slide 79

Slide 79 text

79 / 93

Slide 80

Slide 80 text

Cygwin MinGW Tools for Unix-like environment for Windows 80 / 93

Slide 81

Slide 81 text

81 / 93

Slide 82

Slide 82 text

cmder Not a unix, but better console for windows :) 82 / 93

Slide 83

Slide 83 text

Babun Pre-configured out-of-box unix-like experience of cygwin. 83 / 93

Slide 84

Slide 84 text

결론 84 / 93

Slide 85

Slide 85 text

뭔가 많은 얘기를 한것 같지만 85 / 93

Slide 86

Slide 86 text

익숙해지면 CLI 도 쓸만합니다. 86 / 93

Slide 87

Slide 87 text

어차피 쉘 작업을 피할 수 없다면, 약간의 노력을 들여 피로한 손에게 자유를! 87 / 93

Slide 88

Slide 88 text

단축키 예쁜 쉘 prompt Use ZSH + FASD! 여러가지 Unix 도구들 Vim Plugins (CtrlP, NerdTree) Dotfiles.git

Slide 89

Slide 89 text

당부의 말쐀. 89 / 93

Slide 90

Slide 90 text

여기 있는 내용들을 습득하는 데에는 학습 비용도 크고, 많은 시간이 걸릴지도 모릅니다. 사실 이런거 몰라도 살던눀로 잘 살면 되죠

Slide 91

Slide 91 text

하지만 조금만 노력하면, 언젠가 분명 많은 도움이 될 것입니다.

Slide 92

Slide 92 text

당장 자신에게 도움이 될 것 같은 도구, 팁들부터 조금씩, 천천히 익혀나가보면 어떨까요?

Slide 93

Slide 93 text

Thank You! Slideshow created using remark.