å人çãªShellTipsãã¾ã¨ãã¦ã¿ã
naoya_itoの火を噴いたシェルtips - Togetter
ãããèªãã§ãµã¨æ¸ããããªã£ãã®ã§ãã¡ãªã¿ã«åã¯bash使ã£ã¦ãã¾ãã
CTRLã使ã£ã便å©ç³»
ã¾ããUNIXãªæä½ãããã
ãã¼ãã¤ã³ã | æå³ |
---|---|
CTRL + s | |
CTRL + q | ä¸è¨è§£é¤ |
CTRL + z | ããã¯ã°ã©ã¦ã³ãã«. fgã§æ»ã |
CTRL + l | ç»é¢ãã¯ãªã¢ãclearã¨åç |
CTRL + c | ç¾å¨ã®å¦çãåæ¢ |
CTRL + d | exitã¨åç |
CTRL + r | historyããã³ãã³ãæ¤ç´¢ |
emacsã£ã½ããã¤
ã©ã£ã¡ãã¨ããã¨ãã¼æä½ã«è¿ããåºæ¬ã¯emacsãmetaã¯åã¯optionã«å²ãå½ã¦ã¦ããã¨ãããã触ããã人ã¯ESCã§OKã
ãã¼ãã¤ã³ã | æå³ |
---|---|
CTRL + a | è¡é |
CTRL + e | è¡æ« |
CTRL + f | â |
CTRL + b | â |
CTRL + p | â |
CTRL + n | â |
CTRL + k | ãã¾ããã«ã¼ã½ã«ããå¾ããåãåã |
CTRL + y | è²¼ãä»ã |
CTRL + j / CTRL + m | returnã¨åç |
meta + f | ã¯ã¼ãã¸ã£ã³ãï¼åï¼ |
meta + b | ã¯ã¼ãã¸ã£ã³ãï¼å¾ï¼ |
ããã¤ããå°å³ãªã³ãã³ã
ã³ãã³ãã¨ãããtipsçãªãã®ã
ã¯ã³ã©ã¤ãã¼ã§æ¡ä»¶å¼
||ã¨ã&&ã§æ¡ä»¶æ¸ãããã£ã¬ã¯ããªããªããã°mkdirã¿ãããªã¨ãã«ä½¿ãã以ä¸ã®ãããªæãã
test -d ~/foo || mkdir ~/foo
ãã¡ã¤ã«ã®ããã¯ã¢ãããã©ã¯ã«
fooã¨ãããã¡ã¤ã«ã®ããã¯ã¢ãããã¨ãã¨ãã«ä»¥ä¸ã®ããã«ãã¦æ¸ããã
cp -ip foo{,.bak}
ããã«æ¥ä»ãä»ãããå ´åã¯ãããªæãã§æ¸ãã
cp -ip foo{,.`date +%Y%m%d`}
æ¨æºåºåããrootã§ãã¡ã¤ã«ãä½ãããã¨ãã¯tee
ãªãã¤ã¬ã¯ãã§ãã£ã¦ããããã ãã©ãã¡ãã£ã¨ãããã®ã§teeã³ãã³ãã使ããã¨ãå¤ãã
echo hogehoge | sudo tee /path/to/file
ãããªãããã§ãã¢ããã¥ã¡ã³ãã¨çµã¿åããããã¨ããããæé æ¸ãæ¸ãã¨ããªããã¯ä¾¿å©ãæé æ¸ã§viã¨ãåå¼ã
sudo tee /path/to/file << EOF hogehoge fugafuga EOF
xargsã§1è¡ãã¤å®è¡ããã
find . | xargs echo
ã¿ããã«ããã¨ãechoã®å¼æ°ã«å ¨é¨ããã£ã¦ãã¦ãã¾ãã1è¡ãã¤å®è¡ãããå ´åã¯ä»¥ä¸ã®ããã«ãã¦ããã
find . | xargs -n1 echo
xargsãªãã¦ãfindã ãã§exec
xargsãã¿ã«ãªãã¨findã ãã§ã§ãããçãªè©±ã«ãªãã®ã§ãã£ã¡ãããããªæãã§æ¸ããã
find . -exec echo {} \;
ç¹å®ã®PIDãã¡ã¤ã«ã®ããã»ã¹ãã§ãã¯
pidãã¡ã¤ã«ããããã»ã¹èª¿ã¹ããã¨ãã£ã¦ããã
ps `cat /var/run/httpd.pid `
åå解決ã«ã¯hostã³ãã³ã
ååãã²ãã¨ãã«ã¡ããã¨è¦ããã¨ãã¯digã¨ãã¤ãããã©ããã åç´ã«IPã¢ãã¬ã¹ãå¼ã£å¼µãããã¨ãã¯ãã£ã¡ã®ã»ããã©ã¯ãããããã°ãnslookupã¯ãããããã£ã¦10å¹´ãããåã«è¨ãããã
host nanapi.jp
pushd / popd
ä¸æ¦ä»ã®ãã£ã¬ã¯ããªã«ç§»åãã¦ããæ»ãããã¨ãã¨ããã使ããpushdã§ã«ã¬ã³ããã£ã¬ã¯ããªãã¹ã¿ãã¯ã«ãã¾ã£ã¦ããã
grep -ir
findãã¦grepãã¦ã人è¦ããããã©ãgrepã ãã§ã§ãããã¾ãagã¤ãããã©ã
grep -ir foo *
resetã³ãã³ã
ãã¤ããªãã¡ã¤ã«ãééã£ã¦catããããã¦ãã¾ã£ã¦ã¿ã¼ããã«ä¸ã®è¡¨ç¤ºããããããªã£ãæãresetãæã¦ã°OKã§ãã
reset
emacsãdaemonåãã¦ãã
emacsã¯--daemonã¨ãããªãã·ã§ã³ã§daemonåã§ããããã¨ã¯emacsclientããã¤ãªãã ãã以ä¸ã®è¨è¿°ãbashrcã«å ¥ãã¦ããã
alias emd="emacs --daemon" alias emc="emacsclient -c" alias ekill="emacsclient -e '(progn (defun yes-or-no-p (p) t) (kill-emacs))'"
ã¨ããããæãã¤ãããããã§ãããªã¨ããã