Boost Your Shell Experience

Boost Your Shell Experience

당신의 터미널을 윤택하게 해줄 비밀 레시피 (2014)

Jongwook Choi

July 04, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

93 slides
  1. Hello Linux !? you@server ~ $ cowsay "How are you

    doing with your Linux?" ____________________________________ < How are you doing with your Linux? > ------------------------------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || 2 / 93
  2. 이 폭탄을 해제하려면 올바른 tar 명령어를 입력하세요. 기회는 단 한번

    구관링 ㄴㄴ. 10초! http://xkcd.com/1168/ Yes, unix is hard.
  3. 생각했던 제목 후보들 터미널 삶을 편하게 해주는 마법의 레시피 생산성

    부스팅 스팀팩 여러분의 손을 편안하게 해줄게요 리눅스 안쓸수 없다면 잘쐁시다 아직도 bash 쓰니? 저거 vim 맞어? 6 / 93
  4. 왜 이런걸 알아야 하는가? 1. 우리들은 서버 작업을 피할 수가

    없습니다. 2. 로컬 머신이 아닌 Command-Line 작업환경도 개선할 수 있습니다. 3. UNIX가 아닌 로컬 머신에도 터미널이 있으면 여러가지 도구들을 쓸 수 있습니다. 왜 윈도우는 curl 없나요 10 / 93
  5. Covered Topics ZSH tmux, fasd, .. 여러가지 유용한 커맨드라인 도구들

    vim plugins 설정 관리하는 방법 윈도우 유저를 위하여.. 11 / 93
  6. 유용한 단축키들을 알아둡시다. 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
  7. 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
  8. 왜 ZSH를 써야 합니까? 더 이상 설명이 必要韓紙? 똑똑한 autocomplete

    및 interactive UI fuzzy string/pattern 매칭 Path globbing (e.g. **/*.java) 오타 자동교정 다행히도.. Bash 와 (거의 완벽한) 호환성 남들이 많이 써요: 시눀의 눀세! + Configuration Framework 24 / 93
  9. 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
  10. FASD: Command-line productivity booster 가장 최근(recently) 및 자주 접근한(directory) 디렉토리나

    파일을 기억하 고 있다가 빠르게 접근할 수 있도록 해준다. 27 / 93
  11. 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
  12. 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
  13. Vim (something) | vim - Examples # 7월 1일 (시간별)

    로그 다 보고 싶다. $ cat logs.2014-07-01*.log | vim - # svn diff는 colorized output이 안됨.. $ svn diff | vim - 33 / 93
  14. 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
  15. 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
  16. 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
  17. awk 정말 다양한 기능이 가능하지만.. 보통 특정 column 추출할 때

    많이 쐁니다. $ ps aux | awk '{print $2}' # -F : 구분자 설정 $ cat data.csv | awk -F'\t' '{print $2}' 40 / 93
  18. 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
  19. 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
  20. 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
  21. 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
  22. 그 외 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
  23. 도구: 설치법 builtin commands 패키지 매니저를 통해 설치 CentOS :

    yum install [blah] Ubuntu : apt-get install [blah] Mac OS X : brew install [blah] 48 / 93
  24. 도구: 설치법 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
  25. 도구: 설치법 그래도 없네? 바이너리 하나인 경우 (e.g. jq) 그냥

    binary 를 /usr/local/bin 등에 복사한다. 컴파일 설치 !! 헬게이트의 시작 Node, Python, Ruby 기반의 툴들 npm, pip, gem 등으로 설치해야 한다. 시스템 전역에 설치가 곤란한 경우에는 nvm, virtualenv, rvm 등 으로 계정별 가상 환경을 만들고 신나게 깔면 된다. 이쯤되면 그냥 안 쓰고 싶다 50 / 93
  26. Real-world examples access log: 가장 많이 접속한 30명 찾기 cat

    access.log | awk -F'\t' '{print $1}' \ | sort | uniq -c | sort -nr | head -n30 맵리듀스!? 52 / 93
  27. A minimal ~/.vimrc " ... set nocompatible set backspace=indent,eol,start "

    더 가독성 있는 색깔.." set bg=dark " 줄 번호 보이기." set number " better <tab> suggestion" set wildmenu set wildmode=list:longest,full What's in your .vimrc file? vim-sensible 59 / 93
  28. 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
  29. 고수의 방법 vim 설정을 git repository로 관리하고 git submodule 로

    등록 vundle, neobundle, vim-addon-manager, vim-plug 등과 같은 플러그인 매니저를 활용 63 / 93
  30. git clone to the rescue 새로운 머신이 있는가? $ git

    clone [email protected]:myusername/dotfiles ~/.dotfiles $ cd ~/.dotfiles && ./install.sh 설정 동기화가 필요한가? $ cd ~/.dotfiles && git pull 76 / 93
  31. 단축키 예쁜 쉘 prompt Use ZSH + FASD! 여러가지 Unix

    도구들 Vim Plugins (CtrlP, NerdTree) Dotfiles.git
  32. 여기 있는 내용들을 습득하는 데에는 학습 비용도 크고, 많은 시간이

    걸릴지도 모릅니다. 사실 이런거 몰라도 살던눀로 잘 살면 되죠

More Decks by Jongwook Choi

Other Decks in Programming