mirror of
https://github.com/xmengnet/the-art-of-command-line.git
synced 2024-12-24 10:06:28 +08:00
617 lines
47 KiB
Markdown
617 lines
47 KiB
Markdown
ð
|
||
*[ÄeÅ¡tina](README-cs.md) â [Deutsch](README-de.md) â [ÎλληΜικά](README-el.md) â [English](README.md) â [Español](README-es.md) â [Français](README-fr.md) â [Indonesia](README-id.md) â [Italiano](README-it.md) â [æ¥æ¬èª](README-ja.md) â [íêµìŽ](README-ko.md) â [Português](README-pt.md) â [RomânÄ](README-ro.md) â [Ð ÑÑÑкОй](README-ru.md) â [SlovenÅ¡Äina](README-sl.md) â [УкÑаÑÐœÑÑка](README-uk.md) â [ç®äœäžæ](README-zh.md) â [ç¹é«äžæ](README-zh-Hant.md)*
|
||
|
||
# The Art of Command Line
|
||
|
||
[![質åããŠã¿ãã](https://img.shields.io/badge/%3f-Ask%20a%20Question-ff69b4.svg)](https://airtable.com/shrzMhx00YiIVAWJg)
|
||
|
||
[![https://gitter.im/jlevy/the-art-of-command-lineã§ãã£ããã«åå ããã](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jlevy/the-art-of-command-line?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||
|
||
- [ã¡ã¿æ
å ±](#ã¡ã¿æ
å ±)
|
||
- [åºæ¬](#åºæ¬)
|
||
- [æ¥åžžçã«äœ¿ããã®](#æ¥åžžçã«äœ¿ããã®)
|
||
- [ãã¡ã€ã«ãšããŒã¿ã®åŠç](#ãã¡ã€ã«ãšããŒã¿ã®åŠç)
|
||
- [ã·ã¹ãã ã®ãããã°](#ã·ã¹ãã ã®ãããã°)
|
||
- [ã¯ã³ã©ã€ããŒ](#ã¯ã³ã©ã€ããŒ)
|
||
- [ç®ç«ããªãã䟿å©ãªãã®](#ç®ç«ããªãã䟿å©ãªãã®)
|
||
- [OS Xçšã®ãã®](#os-xçšã®ãã®)
|
||
- [Windowså°çš](#windowså°çš)
|
||
- [ãããªããªãœãŒã¹](#ãããªããªãœãŒã¹)
|
||
- [å
責äºé
](#å
責äºé
)
|
||
|
||
![curl -s 'https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md' | egrep -o '`\w+`' | tr -d '`' | cowsay -W50](cowsay.png)
|
||
|
||
ã³ãã³ãã©ã€ã³ã§æµããããã«æäœãã§ãããšããããšã¯ã軜ãèŠããããä»äººããç解ãããªãã¹ãã«ã ãšã¿ãªãããããšãããã ãããããããã®ã¹ãã«ã¯ãæããã«ãããåãããããã¯åããããšã³ãžãã¢ãšããŠã®ããªãã®æè»æ§ãçç£æ§ãæ¹åããŠããããã®ã ãããã§ã¯ãLinuxã§ã³ãã³ãã©ã€ã³ã䜿ãäžã§äŸ¿å©ã ãšæã£ãã¡ã¢ãTipsã®æ°ã
ãæããŠã¿ãããããã®ã¯åºç€çã ããéåžžã«è©³ãããã®ãæŽç·Žããããã®ãææ§ãªãã®ãããããã®ããŒãžã¯ãããªã«é·ããã®ã§ã¯ãªãããããã«æžããŠããããšã®å
šãŠã䜿ã£ããæãåºãããšãã§ããã°ãããªã詳ãããªããã ããã
|
||
|
||
ãã®ããã¥ã¡ã³ãã¯[å€ãã®å·çè
ãšç¿»èš³è
](AUTHORS.md)ã«ããææã§ããã
|
||
ããã«æžããŠããããšã®å€ãã¯ã[å
ã
](http://www.quora.com/What-are-some-lesser-known-but-useful-Unix-commands)[Quora](http://www.quora.com/What-are-some-time-saving-tips-that-every-Linux-user-should-know)ã«[æžãããŠ](http://www.quora.com/What-are-the-most-useful-Swiss-army-knife-one-liners-on-Unix)ãããã®ãå€ãããããåªãã人ãã¡ãããã«æ¹åæ¡ãåºãããšãã§ããGitHubã«çœ®ãã®ãããã®ã§ã¯ãšæã£ãã
|
||
ã³ãã³ãã©ã€ã³ã«ã€ããŠçåããããªã[**質åããŠã¿ãã**](https://airtable.com/shrzMhx00YiIVAWJg) ãšã©ãŒãæ¹åç¹ãèŠã€ããã[**è²¢ç®ããŠã¿ãã**](/CONTRIBUTING.md)!
|
||
|
||
## ã¡ã¿æ
å ±
|
||
|
||
察象 :
|
||
|
||
- ãã®ã¬ã€ãã¯ãåå¿è
åãã§ãçµéšè
åãã§ããããå¹
åºã(æžããŠããããšã¯å
šãŠéèŠ)ããã€æ確ã§(å€ãã®ã±ãŒã¹ã«å¯ŸããŠå
·äœçãªäŸãä»ãã)ããããŠç°¡æœ(ä»ã®å Žæã§èŠã€ãããããããªéèŠã§ãªãããšãè±ç·ããããšã¯çã)ã§ããããšããŽãŒã«ã«ããŠãããåé
ç®ã¯ãå€ãã®å Žé¢ã«ãããŠå¿
é ã§ããããä»ã®æ¹æ³ã«æ¯ã¹ãŠåçã«æéãç¯çŽããŠãããã ããã
|
||
- [OS Xçšã®ãã®](#os-x-only)ãé€ããLinuxåãã®å
容ãšãªã£ãŠããããã®å€ãã¯åçš®Linuxããã³MacOS(ãããã¯Cygwin)ã§ã䜿ããã ããã
|
||
- ã€ã³ã¿ã©ã¯ãã£ããªBashã䜿ãããšãæ³å®ããŠããããå€ãã®é
ç®ã¯ä»ã®ã·ã§ã«ãBashã®ã¹ã¯ãªããã§ã䜿ããã ããã
|
||
- (ãã®ãªããžããªãž)çµã¿èŸŒãã¡ãªãããããã®ã§ããã°ãæšæºUnixã³ãã³ããããã±ãŒãžã€ã³ã¹ããŒã«ã³ãã³ããå«ããã
|
||
|
||
泚æ :
|
||
|
||
- 1ããŒãžå
ã«åããããã«ãå
容ã«ã¯æé»çã«æžãããŠããããšããããããã§åãããããç¥ã£ããã³ãã³ããåããã°ã詳现ãã©ããã§èª¿ã¹ãããããããã¯ã§ããã ãããæ°ããããã°ã©ã ãã€ã³ã¹ããŒã«ããã«ã¯ã`apt-get`ã`yum`ã`dnf`ã`pacman`ã`pip`ã`brew`(ã©ããé©ãããã®)ã䜿ããã
|
||
- ã³ãã³ãããªãã·ã§ã³ããã€ããå解ããŠç解ããæå©ãã«ã[Explainshell](http://explainshell.com/)ã䜿ããã
|
||
|
||
## åºæ¬
|
||
|
||
- åºæ¬çãªBashãåŠãŒããå®éã®ãšããã`man bash`ã¯çµæ§ç°¡åã«ç解ã§ããããããªã«é·ããªãã®ã§ãããã§äžéãã®ããšã¯åããããã以å€ã®ã·ã§ã«ãããããBashã¯åŒ·åã ããåžžã«äœ¿çšå¯èœã§ãããšããå©ç¹ããã(èªåã®PCã«å
¥ããŠããŸã£ããšèšã£ãŠzshãfishãªã©*ã ã*ãåŠãã§ããŸããšãæ¢åã®ãµãŒãã觊ããªããŠã¯ãªããªãæãªã©ã«å¶çŽãåºãŠããŸã)ã
|
||
|
||
- ããã¹ããšãã£ã¿ã®ã©ããæäœ1ã€ã«ç¿çãããã`nano`ãšãã£ã¿ã¯ç·šéã®åºæ¬æäœ(éããä¿®æ£ãããä¿åãããæ€çŽ¢ãã)ãåŠã¶æãã·ã³ãã«ãªæ¹æ³ã®ã²ãšã€ã ãã¿ãŒããã«å
ã§é©åœã«ãã®ãæžãã«ããã£ãŠä»ã«å
šã代æ¿åããªããšããç¹ã§ãçæ³çã«ã¯Vim(`vi`)ãããã ãã(éåžžã¯Emacsãé«æ©èœãªIDEãææ°ã®ãã£ããããšãã£ã¿ãã¡ã€ã³ã«äœ¿ã£ãŠãããšããŠã)ã
|
||
|
||
- `man`ã§ã®ããã¥ã¡ã³ãã®èªã¿æ¹ãç¥ãã(ç¥ããããã®ããã«æžããšã`man man`ã§ã»ã¯ã·ã§ã³çªå·ãåãããäŸãã°1ã¯ãäžè¬çãªãã³ãã³ãã5ã¯ãã¡ã€ã«ããã®ãäœæ³ã8ã¯ç®¡çã«ã€ããŠãšãã£ãå
·å)ã`apropos`ã§manããŒãžãæ¢ãããã³ãã³ãã«ãã£ãŠã¯å®è¡å¯èœãã¡ã€ã«ã§ã¯ãªãBashã®ãã«ãã€ã³ã³ãã³ãã§ããããšãç解ãã`help`ã`help -d`ã§ãã«ããèŠãããããšãç¥ããã
|
||
|
||
- `>`ã`<`ã`|`ã䜿ã£ããã€ãã«ããå
¥åºåã®ãªãã€ã¬ã¯ã·ã§ã³ãåŠãŒãã`>`ã¯åºåãã¡ã€ã«ãäžæžãã`>>`ã¯è¿œèšãšãªããstdout(æšæºåºå)ãšstderr(æšæºãšã©ãŒåºå)ãåŠãŒãã
|
||
|
||
- `*`(ãŸãã¯`?`ã`[`...`]`)ã䜿ã£ããã¡ã€ã«ã°ããå±éãã¯ã©ãŒããŒã·ã§ã³ãããã«ã¯ã©ãŒã`"`ãšã·ã³ã°ã«ã¯ã©ãŒã`'`ã®éããåŠãŒã(詳ããã¯ãã®åŸã®å€æ°å±éã®é
ãåç
§)ã
|
||
|
||
- `&`ã**ctrl-z**ã**ctrl-c**ã`jobs`ã`fg`ã`bg`ã`kill`ãªã©ãBashã®ãžã§ã管çã«ã€ããŠè©³ãããªããã
|
||
|
||
- `ssh`ã«ã€ããŠç¥ããšãšãã«ã`ssh-agent`ã`ssh-add`ã䜿ã£ããã¹ã¯ãŒããªãã®èªèšŒã®åºæ¬ã«ã€ããŠç解ãããã
|
||
|
||
- ãã¡ã€ã«ç®¡çã«ã€ããŠã`ls`ã`ls -l`(ç¹ã«ã`ls -l`ã®ååãäœãæå³ãããç解)ã`less`ã`head`ã`tail`ã`tail -f`(ãŸãã¯`less +F`)ã`ln`ãš`ln -s`(ããŒããªã³ã¯ãšãœãããªã³ã¯ã®éããšããããã®å©ç¹ã®ç解)ã`chown`ãš`chmod`ã`du`(ãã£ã¹ã¯äœ¿çšéãŸãšããç°¡åã«èŠããªã`du -hs *`)ããã¡ã€ã«ã·ã¹ãã 管çã«ã€ããŠã¯ã`df`ã`mount`ã`fdisk`ã`mkfs`ã`lsblk`ãinodeã«ã€ããŠã¯ã`ls -i`(ãŸã㯠`df -i`)ã
|
||
|
||
- åºæ¬çãªãããã¯ãŒã¯ç®¡çã«ã€ããŠã`ip`ãããã¯`ifconfig`ã`dig`ã`traceroute`ã `route`ã
|
||
|
||
- `git`ã®ãããªããŒãžã§ã³ç®¡çã·ã¹ãã ãåŠãã§äœ¿ã£ãŠã¿ããã
|
||
|
||
- æ£èŠè¡šçŸã«ã€ããŠè©³ããç¥ããã`grep`ã`egrep`ã®è²ã
ãªãã©ã°ãåãããŠã`-i`ã`-o`ã`-v`ã`-A`ã`-B`ã`-C`ãšãã£ããªãã·ã§ã³ã¯ç¥ã£ãŠãããŠæã¯ãªãã
|
||
|
||
- `apt-get`ã`yum`ã`dnf`ã`pacman`(ãã£ã¹ããªãã¥ãŒã·ã§ã³ã«ãã£ãŠéã)ãšãã£ãã³ãã³ãã§ããã±ãŒãžãæ¢ãããã€ã³ã¹ããŒã«ããæ¹æ³ãåŠãŒããPythonããŒã¹ã®ã³ãã³ãã©ã€ã³ããŒã«ãã€ã³ã¹ããŒã«ããã®ã«ã`pip`ãå¿
èŠã (åŸã«åºãŠããããã€ãã®ã³ãã³ãã¯`pip`ã§ã€ã³ã¹ããŒã«ããã®ãäžçªç°¡å)ã
|
||
|
||
|
||
## æ¥åžžçã«äœ¿ããã®
|
||
|
||
- Bashã§ã¯ãåŒæ°ãè£å®ããŸãã¯å©çšå¯èœãªã³ãã³ããåæããã®ã«**ã¿ã**ã䜿ããã³ãã³ãå±¥æŽããæ€çŽ¢ããã®ã«**ctrl-r**ã䜿ãã(æ€çŽ¢ããŒãå
¥åããåŸã**ctrl-r**ãç¹°ãè¿ãå
¥åããããšã§æ¬¡ãã次ãžãšæ€çŽ¢çµæãéãããšãã§ããã**Enter**ã§èŠã€ãã£ãã³ãã³ãã®å®è¡ãšãªãã**Enter**ã§ã¯ãªãå³ã«ãŒãœã«ããŒãæŒããå Žåã¯èŠã€ãã£ãã³ãã³ããå
¥åãããç¶æ
ã«ãªãã)
|
||
|
||
- Bashã§ã¯ãæåŸã®åèªãåé€ããã®ã«ã¯**ctrl-w**ãè¡é ãŸã§å
šãŠåé€ããã«ã¯**ctrl-u**ã䜿ããåèªããšã«ç§»åããã«ã¯**alt-b**ãŸãã¯**alt-f**ãè¡é ã«ç§»åããã«ã¯**ctrl-a**ãè¡æ«ã«ç§»åããã«ã¯**ctrl-e**ãè¡æ«ãŸã§åé€ããã«ã¯**ctrl-k**ãç»é¢ã®ã¯ãªã¢ã¯**ctrl-l**ã§ãããBashã«ãããããã©ã«ãã®ããŒå²ãåœãŠãå
šãŠèŠãã«ã¯`man readline`ãåç
§ãããããåºãŠãããäŸãã°ã**alt-.**ã¯åã®åŒæ°ãé çªã«è¡šç€ºãã**alt-***ã¯ã°ãããå±éããã
|
||
|
||
- vi颚ã®ããŒå²ãåœãŠã奜ããªãã`set -o vi`ãå®è¡ãããã(å
ã«æ»ããããšãã¯`set -o emacs`)
|
||
|
||
- é·ãã³ãã³ããç·šéãããšãã«ããšãã£ã¿ãèšå®ããåŸã§(äŸãã°`export EDITOR=vim`)ã**ctrl-x** **ctrl-e**ã«ãã£ãŠç·šéäžã®ã³ãã³ããè€æ°è¡ã®ç·šéã®ããã«æå®ãããšãã£ã¿ã§éããããvi颚ã®å Žåã¯ã**escape-v**ã
|
||
|
||
- æè¿å®è¡ããã³ãã³ãã確èªãããªã`history`ã`!n`ãšç¶ããããšã§(nã¯ã³ãã³ã暪ã«è¡šç€ºãããæ°å)å床å®è¡ã§ããã**ctrl-r**ã**alt-.**ã§çšã¯è¶³ããã ãããã`!$`(çŽåã®åŒæ°)ã`!!`(çŽåã®ã³ãã³ã)ãšãã£ãçç¥åœ¢ãããããããã
|
||
|
||
- `cd`ã§ããŒã ãã£ã¬ã¯ããªãžã®ç§»åãããŒã ãã£ã¬ã¯ããªã«é¢é£ãããã¡ã€ã«ã«ã¢ã¯ã»ã¹ããå Žåã¯ãã¬ãã£ãã¯ã¹`~`ãã€ãã(äŸ: `~/.bashrc`)ã`sh`ã¹ã¯ãªããã®äžã§ã¯`$HOME`ã§ããŒã ãã£ã¬ã¯ããªãè¡šãããšãã§ããã
|
||
|
||
- åã®ã¯ãŒãã³ã°ãã£ã¬ã¯ããªã«æ»ããªã`cd -`
|
||
|
||
- éäžãŸã§ã³ãã³ããå
¥åããããã©å¿å€ããããæã¯ã**alt-#**ãæã€ãšè¡é ã«`#`ãæ¿å
¥ãããã³ã¡ã³ããšããŠå
¥åããã(**ctrl-a**ã**#**ã**enter**ã§ãåã)ãããã¯åŸã§ã³ãã³ãå±¥æŽããæ€çŽ¢ã§ããã
|
||
|
||
- `xargs`(ãŸãã¯`parallel`)ã䜿ãããéåžžã«åŒ·åãè¡ããšã«ããã€ã®ã¢ã€ãã ãå®è¡ããã(`-L`)ãã䞊å床(`-P`)ãå¶åŸ¡ã§ãããæ£ããå®è¡ããããå®ãã§ãªããªãããŸã`xargs echo`ããŠã¿ãã°ããã`-I{}`ã䟿å©ãäŸãã°ä»¥äžã®éãã
|
||
|
||
```bash
|
||
find . -name '*.py' | xargs grep some_function
|
||
cat hosts | xargs -I{} ssh root@{} hostname
|
||
```
|
||
|
||
- `pstree -p`ã¯ããã»ã¹ããªãŒã衚瀺ããã®ã«äŸ¿å©ã
|
||
|
||
- `pgrep`ã`pkill`ã§ãããã»ã¹åã§æ€çŽ¢ãããã·ã°ãã«ãéãã(`-f`ã䟿å©)ã
|
||
|
||
- ããã»ã¹ã«éããè²ã
ãªã·ã°ãã«ãç¥ã£ãŠããããäŸãã°ãããã»ã¹ããµã¹ãã³ãããã«ã¯`kill -STOP [pid]`ã䜿ããå
šçš®é¡èŠããªãã`man 7 signal`ã
|
||
|
||
- ããã¯ã°ã©ãŠã³ãããã»ã¹ããã£ãšå®è¡ãç¶ããããªã`nohup`ãããã¯`disown`ã䜿ããã
|
||
|
||
- `netstat -lntp`ã`ss -plat`ã§ãã©ããªããã»ã¹ããªãã¹ã³ããŠããã確èªããã(UDPãªã`-u`ãä»ãã)ã
|
||
|
||
- éãããŠãããœã±ããããã¡ã€ã«ãèŠãã«ã¯`lsof`ãåç
§ã
|
||
|
||
- `uptime`ã`w`ã«ãã£ãŠã·ã¹ãã ã®çšŒåæéã調ã¹ãããã
|
||
|
||
- `alias`ã«ãã£ãŠããå©çšããã³ãã³ãã®ãšã€ãªã¢ã¹(ã·ã§ãŒãã«ãã)ãäœæã§ãããäŸãã°ã`alias ll='ls -latr'`ã§ã¯æ°ãããšã€ãªã¢ã¹ã§ãã`ll`ãäœæããã.
|
||
|
||
- ãã䜿ããšã€ãªã¢ã¹ãã·ã§ã«èšå®ãæ©èœã`~/.bashrc`ã«ä¿åãã[ãã°ã€ã³ã·ã§ã«ã«åæ ããã](http://superuser.com/a/183980/7106)ãããã§å
šãŠã®ã»ãã·ã§ã³ã§ããªãã®èšå®ãå©çšã§ããã
|
||
|
||
- ãã°ã€ã³æã«å®è¡ãããŠã»ããã³ãã³ããç°å¢å€æ°ã`~/.bash_profile`ã«èšèŒãããç»é¢ããã®ãã°ã€ã³ã`cron`ãžã§ãã§èµ·åãããã·ã§ã«ã«ã¯å¥ã®èšå®ãå¿
èŠã ã
|
||
|
||
- Gitã§æ§ã
ãªãã·ã³ã®èšå®ãã¡ã€ã«(äŸ:`.bashrc`ã`.bash_profile`)ãåæããããã
|
||
|
||
- 空çœãå«ãå€æ°ããã¡ã€ã«åã«ã¯æ³šæãå¿
èŠã ãBashå€æ°ã«ã¯ã¯ãªãŒããã€ãããããããªé¢šã«`"$FOO"`ã
|
||
ãã¡ã€ã«åã®åºåããšããŠãã«æåãæå®ããå Žåã«ã¯`-0`ã`-print0`ãªãã·ã§ã³ãä»äžããããäŸ: `locate -0 pattern | xargs -0 ls -al` or `find / -print0 -type d | xargs -0 ls -al`ã空çœãå«ãã ãã¡ã€ã«åãç¹°ãè¿ãå®è¡ããããã«ã¯ãIFS=$'\n'`ã䜿ã£ãŠIFSãæ¹è¡ã®ã¿ã«ãããã
|
||
|
||
- Bashã¹ã¯ãªããã§ã¯ã`set -x`ã§ãããã°åºåãåºãã(`set -v`ã¯ãå®è¡ãããã³ãã³ããå€æ°åãã³ã¡ã³ããªã©ããã®ãŸãŸåºåãã)ãç¹å¥ãªçç±ããªãéãå³æ Œã¢ãŒã(strict mode)ã䜿ãã`set -e`ã§ãšã©ãŒæ(0以å€ã®çµäºã³ãŒãæ)ã«åŒ·å¶çµäºããããã«ã`set -u`ã«ãã£ãŠæªå®çŸ©ã®å€æ°ã®å©çšãæ€ç¥ããã€ãã®ãšã©ãŒãå³æ Œã«æ±ãããã«`set -o pipefail`ã䜿ãã(ããã¯ã¡ãã£ãšåŸ®åŠãã)ãããè€éãªã¹ã¯ãªãããªããEXITãŸãã¯ERRã·ã°ãã«ã«å¯ŸããŠ`trap`ã䜿ããã䜿ãå Žé¢ãšããŠã¯ä»¥äžã®å Žåã®ããã«ãšã©ãŒãæ€ç¥ããŠã¡ãã»ãŒãžãåºåãããšã:
|
||
|
||
```bash
|
||
set -euo pipefail
|
||
trap "echo 'error: Script failed: see failed command above'" ERR
|
||
```
|
||
|
||
- Bashã¹ã¯ãªããã§ã¯ãã³ãã³ãã®ã°ã«ãŒããäœãã®ã«ãµãã·ã§ã«(äžžæ¬åŒ§ã§å²ãŸããéšå)ã䟿å©ãäžæçã«ã¯ãŒãã³ã°ãã£ã¬ã¯ããªã移åãããšããããããäŸã
|
||
|
||
```bash
|
||
# ã«ã¬ã³ããã£ã¬ã¯ããªã§äœãå®è¡
|
||
(cd /some/other/dir && other-command)
|
||
# å
ã®ãã£ã¬ã¯ããªã§äœæ¥ç¶è¡
|
||
```
|
||
|
||
- Bashã§ã¯ãããããã®å€æ°å±éã®çš®é¡ãããããšãèŠããŠããããå€æ°ãååšããããã§ãã¯ãããªãã`${name:?error message}`ãäŸãã°ãBashã¹ã¯ãªããã1ã€ã®åŒæ°ãåãå¿
èŠããããªãã`input_file=${1:?usage: $0 input_file}`ãšã ãæžãã°ãããç®è¡åŒã®å±éã¯ã`i=$(( (i + 1) % 5 ))`ãã·ãŒã±ã³ã¹ã¯`{1..10}`ãæååã®ããªãã³ã°ã¯`${var%suffix}`ãš`${var#prefix}`ãäŸãã°`var=foo.pdf`ã®æã`echo ${var%.pdf}.txt`ãšãããš`foo.txt`ãåºåã«ã
|
||
|
||
- `{`...`}`ã䜿ã£ãäžæ¬åŒ§å±éã«ãã£ãŠã䌌ããããªã³ãã³ããè€æ°åå
¥åããªããŠæžããäŸãã°ã `mv foo.{txt,pdf} some-dir` (äž¡æ¹ã®ãã¡ã€ã«ã移åããã), `cp somefile{,.bak}` (`cp somefile somefile.bak` ãšå±éããã)ã`mkdir -p test-{a,b,c}/subtest-{1,2,3}` (ãã¹ãŠã®å¯èœãªçµã¿åããã§ãã£ã¬ã¯ããªãäœããã).
|
||
|
||
- å±éã®é åºã¯æ¬åŒ§âãã«ãããã©ã¡ãŒã¿ãå€æ°ãèšç®æ©å·ãã³ãã³ã眮æ(å·Šããå³)âæåã®åå²âãã¡ã€ã«åã®é ã ã(äŸãã°ã{1..20}ã®ãããªç¯å²ã¯{$a..$b}ãšããããã«ã¯è¡šçŸã§ããªãã`seq`ã`for`ã«ãŒãã䜿ã£ãŠãããªé¢šã«è¡šãããšãã§ããã`seq $a $b or for((i=a; i<=b; i++)); do ... ; done`)
|
||
|
||
- ã³ãã³ãã®åºåã`<(some command)`ã®ããã«ããŠãã¡ã€ã«ã®ããã«æ±ãããäŸãã°ãããŒã«ã«ãšãªã¢ãŒãã®ã®`/etc/hosts`ãæ¯èŒãããªã以äžã®ããã«ãªãã
|
||
|
||
```sh
|
||
diff /etc/hosts <(ssh somehost cat /etc/hosts)
|
||
```
|
||
|
||
- ã¹ã¯ãªãããæžãæã¯å
šãŠã®ã³ãŒããäžæ¬åŒ§ã§å²ãŸãªããŠã¯ãããªããããéãæ¬åŒ§ãæ¬ ããŠãããã·ã³ã¿ãã¯ã¹ãšã©ãŒã§å®è¡ã劚ãããããããã¯ããªããã¹ã¯ãªãããããŠã³ããŒããããšãã«å€æãããïŒäžå®å
šãªã¹ã¯ãªããã®ïŒå®è¡ã«ãã£ãŠéšåçã«webããããŠã³ããŒãããŠããŸãã®ãé²ãããã ã
|
||
```bash
|
||
{
|
||
# Your code here
|
||
}
|
||
```
|
||
|
||
- ããã¢ããã¥ã¡ã³ããã«ãã£ãŠããã¡ã€ã«ããã®[è€æ°è¡ã®ãªãã€ã¬ã¯ã](https://www.tldp.org/LDP/abs/html/here-docs.html)ã®ããã«æ¯ãèãããšãã§ããã
|
||
```
|
||
cat <<EOF
|
||
input
|
||
on multiple lines
|
||
EOF
|
||
```
|
||
|
||
- Bashã§ã¯ã`some-command >logfile 2>&1`ãŸãã¯`some-command &>logfile`ã§æšæºåºåãšæšæºãšã©ãŒåºåã®äž¡æ¹ããªãã€ã¬ã¯ãã§ãããã³ãã³ããæšæºå
¥åã«å¯ŸããŠãã¡ã€ã«ãã³ãã«ãéãã£ã±ãªãã«ããããã°ã€ã³ããŠããã¿ãŒããã«ã«ã²ãã¥ããŠããããã`</dev/null`ããã®ãããç¿æ
£ã
|
||
|
||
- 16é²ãš10é²ã®ASCIIããŒãã«ãèŠãã®ã«`man ascii`ã䜿ãããäžè¬çãªãšã³ã³ãŒãã«é¢ããæ
å ±ã¯ã`man unicode`ã`man utf-8`ã`man latin1`ã䟿å©ã
|
||
|
||
- ã¹ã¯ãªãŒã³ã®åå²ã«`screen`ã[`tmux`](https://tmux.github.io/)ã䜿ãããç¹ã«ããªã¢ãŒãã®SSHã»ãã·ã§ã³ããã¿ãããããã¢ã¿ãããçŽãããããã®ã«æå¹ã`byobu`ã¯screenãtmuxã®æ
å ±ãããå€ãæäŸããŠããã管çã容æã«ãªããã»ãã·ã§ã³æ°žç¶åã ãã®ç°¡åãªãã®ãªã`dtach`ã
|
||
|
||
- SSHã§`-L`ãããã¯`-D`(ãŸãã«`-R`)ã䜿ã£ãããŒããã³ãã«ã®ããæ¹ãèŠããŠãããšäŸ¿å©ãäŸãã°ãªã¢ãŒãã®ãµãŒããããŠã§ããµã€ãã«ã¢ã¯ã»ã¹ããæãªã©ã
|
||
|
||
- SSHã®èšå®ãå°ãã§ãæé©åããŠãããšäŸ¿å©ãäŸãã°ä»¥äžã®`~/.ssh/config`ã®èšå®ã ãšããããã¯ãŒã¯ç°å¢ã«ããæ¥ç¶æãåé¿ããå§çž®ã䜿çšã(垯åã®çŽ°ãåç·ã䜿ã£ãscpãªã©ã§äŸ¿å©)ãããŒã«ã«ã®å¶åŸ¡ãã¡ã€ã«ãæå®ããŠåäžãµãŒããšã®ãã£ãã«ãå€éåããã
|
||
|
||
```
|
||
TCPKeepAlive=yes
|
||
ServerAliveInterval=15
|
||
ServerAliveCountMax=6
|
||
Compression=yes
|
||
ControlMaster auto
|
||
ControlPath /tmp/%r@%h:%p
|
||
ControlPersist yes
|
||
```
|
||
|
||
- ãã以å€ã®SSHãªãã·ã§ã³ã¯ã»ãã¥ãªãã£äžã®åé¡ãããå¯èœæ§ããããããæå¹ã«ããã«ã¯ããµããããããšããã¹ãããšã«æå®ããããä¿¡é Œã§ãããããã¯ãŒã¯å
ã§ã®ã¿äœ¿çšãããªã©æ³šæãå¿
èŠã`StrictHostKeyChecking=no`ã`ForwardAgent=yes`ãªã©ã
|
||
|
||
- [`mosh`](https://mosh.mit.edu/)ã¯UDPã䜿ã£ãsshã®ä»£æ¿ã§ã(ãµãŒããŒåŽã§ã®èšå®ã¯å¿
èŠã§ããã) æç¶çãªæ¥ç¶æã«äŸ¿å©ã
|
||
|
||
- 8é²æ°è¡šçŸã®ãã¡ã€ã«ããŒããã·ã§ã³ã¯ãã·ã¹ãã èšå®ã®éã«äŸ¿å©ã ã`ls`ã®çµæã«ãåºãŠãããééããããã以äžã®ããã«ããŠååŸã§ããã
|
||
|
||
```sh
|
||
stat -c '%A %a %n' /etc/timezone
|
||
```
|
||
|
||
- äœããã®ã³ãã³ãã®åºåãããã€ã³ã¿ã©ã¯ãã£ãã«å€ãéžæãããå Žåã¯ã [`percol`](https://github.com/mooz/percol) ãŸã㯠[`fzf`](https://github.com/junegunn/fzf)ã䜿ããã
|
||
|
||
- (gitã䜿ããªã©)äœããã®ã³ãã³ãã®åºåãããã¡ã€ã«ã«é¢ããããåããããå Žåã¯ã`fpp` ([PathPicker](https://github.com/facebook/PathPicker))ã䜿ããã
|
||
|
||
- ã«ã¬ã³ããã£ã¬ã¯ããª(ãšãµããã£ã¬ã¯ããª)å
šäœãããããã¯ãŒã¯å
ã«å
¬éãããWebãµãŒãã«ãããªãã`python -m SimpleHTTPServer 7777` (ããŒã7777ã§å
¬éãPython 2ã®å Žå)ãããã¯`python -m http.server 7777` (Python 3ã®å Žå)ã
|
||
|
||
- ç¹æš©ã¬ãã«ã§ã³ãã³ããå®è¡ãããšããrootã§ã®å®è¡ã«ã¯`sudo`ãä»ã®ãŠãŒã¶ã®å Žåã¯`sudo -u`ãå©çšã`su` ãŸã㯠`sudo bash`ã§ãã·ã§ã«ããã®ãŠãŒã¶ã§èµ·åããã`su -`ã§rootãŸãã¯ä»ã®ãŠãŒã¶ã§æ°ãã«ãã°ã€ã³ããç¶æ
ãã·ãã¥ã¬ãŒããããã
|
||
|
||
- ç°ãªããŠãŒã¶ãŒã®ã·ã§ã«ã«ç§»ããããšæã¯`su username`ã`su - username`ã䜿ããã"-"ãçšããããšã§ãŸãã§ä»ã®ãŠãŒã¶ãŒããã°ã€ã³ãããã®ããã«ç°å¢ãåŸãããšãã§ãããã¹ã€ããå
ã®ãŠãŒã¶ãŒã®ãã¹ã¯ãŒããæ±ããããã
|
||
|
||
- ã³ãã³ãã©ã€ã³ã®[128K å¶é](https://wiki.debian.org/CommonErrorMessages/ArgumentListTooLong)ã«ã€ããŠç¥ããããã®"Argument list too long"ãšã©ãŒã¯ã¯ã€ã«ãã«ãŒãã«å€§éã®ãã¡ã€ã«ããããããŠããŸã£ããšãã«åºãäžè¬çãªãã®ã ã(ãããããèµ·ããã`find` ã `xargs`ã代æ¿ãšããŠå©ãã«ãªãã ããã)
|
||
|
||
- åºæ¬çãªèšç®(ãã¡ããPythonã®å©çšãäžè¬çã )ã«ã¯`python` interpreterã䜿ãããäŸãã°ãããªé¢šã«ã
|
||
```
|
||
>>> 2+3
|
||
5
|
||
```
|
||
|
||
## ãã¡ã€ã«ãšããŒã¿ã®åŠç
|
||
|
||
- ã«ã¬ã³ããã£ã¬ã¯ããªä»¥äžã®ãã¡ã€ã«ããã¡ã€ã«åã§æ¢ããããªãã`find . -iname '*something*'`ãå Žæãæå®ããã«ãã¡ã€ã«åã§æ€çŽ¢ããããªãã`locate something`ãã€ããã(ãã ã`updatedb`ã¯æè¿äœããããã¡ã€ã«ã¯ã€ã³ããã¯ã¹ããŠããªãã§ãããããšã«æ³šæ)ã
|
||
|
||
- ãœãŒã¹ãããŒã¿ãã¡ã€ã«ã®(`grep -r`ãããé«åºŠãª)äžè¬çãªæ€çŽ¢ã«ã¯ã[`ack`](https://github.com/beyondgrep/ack2)ã[`ag`](https://github.com/ggreer/the_silver_searcher) ("the silver searcher")ããããŠ[`rg`](https://github.com/BurntSushi/ripgrep) (ripgrep)ã䜿ããã
|
||
|
||
- HTMLãããã¹ãã«å€æãããªãã`lynx -dump -stdin`ã
|
||
|
||
- MarkdownãHTMLãªã©æ§ã
ãªçš®é¡ã®ããã¥ã¡ã³ãã®å€æã«ã¯ã[`pandoc`](http://pandoc.org/)ãè©ŠããŠã¿ããšããã
|
||
|
||
- XMLãæ±ããªããŠã¯ãªããªããªãã`xmlstartlet`ã¯å€ããããããŒã«ã ã
|
||
|
||
- JSONã«ã¯[`jq`](http://stedolan.github.io/jq/)ã䜿ããã
|
||
|
||
- YAMLã«ã¯[`shyaml`](https://github.com/0k/shyaml)ãã
|
||
|
||
- ExcelãCSVãã¡ã€ã«ã«ã¯ã[csvkit](https://github.com/onyxfish/csvkit)ã§`in2csv`ã`csvcut`ã`csvjoin`ã`csvgrep`ãªã©ã䜿ããããã«ãªãã
|
||
|
||
- Amazon S3ã«ã¯ã[`s3cmd`](https://github.com/s3tools/s3cmd)ã䟿å©ã§ã[`s4cmd`](https://github.com/bloomreach/s4cmd)ã¯ããã«é«éãAWSé¢é£ã®åŠçã«ã¯Amazonå
¬åŒã®[`aws`](https://github.com/aws/aws-cli)ãšæ¹åçã®[`saws`](https://github.com/donnemartin/saws)ãæ¬ ãããªãã
|
||
|
||
- `sort`ã`uniq`ãããã«uniqã®`-u`ã`-d`ãªãã·ã§ã³ãç¥ã£ãŠããããåŸã«åºãŠããã¯ã³ã©ã€ããŒãåç
§ã`comm`ã確èªããŠãããã
|
||
|
||
- è€æ°ã®ããã¹ããã¡ã€ã«ãæäœããã®ã«ã¯ã`cut`ãš`paste`ã`join`ã¯ç¥ã£ãŠãããã`cut`ã¯ã¿ããªäœ¿ã£ãŠãããã`join`ã¯å¿ããããŠããã
|
||
|
||
- `wc`ãç解ããæ¹è¡(`-l`)ãæå(`-m`)ãåèª(`-w`)ããã€ã(`-c`)ããããã®æ°ãæ¹ãç¥ã£ãŠãããã
|
||
|
||
- æšæºå
¥åããã¡ã€ã«ãšæšæºåºåã®äž¡æ¹ã«åºã`tee`ãç解ãããã`ls -al | tee file.txt`ã®ããã«äœ¿ãã
|
||
|
||
- ã°ã«ãŒãã³ã°ããã£ãŒã«ããå
¥ãæ¿ãããçµ±èšçãªèšç®ãšãã£ããã£ãšè€éãªäœæ¥ã¯[`datamash`](https://www.gnu.org/software/datamash/)ã®å©çšãæ€èšãããã
|
||
|
||
- ãã±ãŒã«ã¯ããœãŒãã®é åº(ç
§åé åº)ãããã©ãŒãã³ã¹ãªã©ãããããã®ã³ãã³ãã©ã€ã³ããŒã«ã«åŸ®åŠãªãšããã§åœ±é¿ããããšãèŠããŠããããå€ãã®Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³ã§ã¯ã`LANG`ãä»ã®ãã±ãŒã«å€æ°ã¯US Englishã®ãããªããŒã«ã«ãªèšå®ã«ãªã£ãŠããããã±ãŒã«ãå€æŽãããšãœãŒãé åºãå€ããããšã«æ³šæãããããŸããåœéå(i18n)察å¿ã®ã«ãŒãã³ã¯ãœãŒãããã®ä»ã®åŠçã*äœåã*é
ãå®è¡ããããã«ãªãç¹ãç¥ã£ãŠããããå Žå(èšå®ã®åŠçãäžææ§ãèŠã€ããåŠçãªã©)ã«ãã£ãŠã¯ã`export LC_ALL=C`ãšããŠããŸãé
ãi18n察å¿ã®åŠçãå®å
šã«ç¡èŠããŠããŸãããšãå¯èœã ã
|
||
|
||
- `TZ=Pacific/Fiji date`ã®ããã«èµ·åæã«å€æ°ãåã«ã€ããããšã§ãç¹å®ã®ã³ãã³ãã®ç°å¢å€æ°ãã»ããããããšãã§ããã
|
||
|
||
- åçŽãªããŒã¿å å·¥ã®ããã«`awk`ãš`sed`ã®åºç€ã身ã«ã€ãããã[ã¯ã³ã©ã€ããŒ](#ã¯ã³ã©ã€ããŒ)ãåç
§ã
|
||
|
||
- 1ã€ãããã¯è€æ°ã®ãã¡ã€ã«å
ã®æååãçŽæ¥çœ®ãæããŠããŸãã«ã¯ã
|
||
|
||
```sh
|
||
perl -pi.bak -e 's/old-string/new-string/g' my-files-*.txt
|
||
```
|
||
|
||
- è€æ°ã®ãã¡ã€ã«åã®å€æŽããã¡ã€ã«å
ã®æ€çŽ¢ã眮æã«ã¯ã[`repren`](https://github.com/jlevy/repren)ã䜿ã£ãŠã¿ããã(å Žåã«ãã£ãŠã¯`rename`ã³ãã³ãã§ãè€æ°ã®ãã¡ã€ã«åå€æŽãã§ãããããã¹ãŠã®Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³ã§æåãåãã§ããããã§ã¯ãªãã®ã§æ³šæãå¿
èŠã)
|
||
|
||
```sh
|
||
# foo -> barãžãšãã¡ã€ã«åããã£ã¬ã¯ããªåããã¡ã€ã«ã®äžèº«ãå€æŽãã:
|
||
repren --full --preserve-case --from foo --to bar .
|
||
# ããã¯ã¢ãããã¡ã€ã«ãå
ã«æ»ã whatever.bak -> whatever:
|
||
repren --renames --from '(.*)\.bak' --to '\1' *.bak
|
||
# äžèšãšåããã®ãrenameã䜿ã£ãŠ:
|
||
rename 's/\.bak$//' *.bak
|
||
```
|
||
|
||
- ããã¥ã¢ã«ããŒãžã«ããããã« `rsync` ã¯éåžžã«é«éã§äžèœãªãã¡ã€ã«ã³ããŒã®éå
·ã§ããããã·ãŒã³éã®ãã¡ã€ã«ãåæãããããšã§ããç¥ãããŠããããããŒã«ã«ã®å Žåã§ãåæ§ã«æçšã§ããããŸãã倧éã®ãã¡ã€ã«ãåé€ãã[é«éãªæ¹æ³](https://web.archive.org/web/20130929001850/http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html)ãšããŠãå©çšã§ãã:
|
||
|
||
```sh
|
||
mkdir empty && rsync -r --delete empty/ some-dir && rmdir some-dir
|
||
```
|
||
|
||
- å®è¡ãã¡ã€ã«ã®é²æãç£èŠãããå Žåã[`pv`](http://www.ivarch.com/programs/pv.shtml)ã[`pycp`](https://github.com/dmerejkowsky/pycp)ã [`pmonitor`](https://github.com/dspinellis/pmonitor)ã[`progress`](https://github.com/Xfennec/progress)ã`rsync --progress`ã䜿ããããããã¯ã¬ãã«ããã¯ã¢ããã¯`dd status=progress`ã ã
|
||
|
||
- ãã¡ã€ã«ããã©ã³ãã ãªè¡ãæãåºãã«ã¯`shuf`
|
||
|
||
- `sort`ã®ãªãã·ã§ã³ãç解ããããæ°å€ã«å¯ŸããŠã¯`-n`ã䜿ãã人éã«ãšã£ãŠèªã¿ããã圢åŒã®æ°å€ã®å Žå(äŸãã°ã`du -h`ã®åºå)ã¯`-h`ã䜿ãããããŒãã©ã®ããã«åŠçãããã®ã(`-t`ã`-k`)ãç¥ãããç¹ã«ãæåã®åã ãã§ãœãŒãããã«ã¯`-k1,1`ãšæžãå¿
èŠãããã`-k1`ã ãšå
šè¡ãèŠãŠãœãŒãããããšããç¹ã«æ³šæã
|
||
|
||
- stableãª(å®å®ãã)ãœãŒã(`sort -s`)ã¯äŸ¿å©ãäŸãã°ãå§ãã«1åç®ã§ãœãŒããããããã2åç®ã§ãœãŒããããªãã`sort -k1,1 | sort -s -k2,2`ãšããã°ããã
|
||
|
||
- Bashã®ã³ãã³ãã©ã€ã³äžã§ã¿ããè¡šçŸããå¿
èŠãããå Žåã**ctrl-v** **[Tab]**ãå
¥åããã`$'\t'` (ã³ãããããªãåŸè
ã®æ¹ããããã)ã
|
||
|
||
- ãœãŒã¹ã³ãŒãã«ããããåœãŠãåºæ¬ã®ããŒã«ã¯`diff`ãš`patch`ã`diff`ã暪䞊ã³ã®`sdiff`ã®çµ±èšæ
å ±ãèŠããªã`diffstat`ãåç
§ãããã`diff -r`ã ãšããã£ã¬ã¯ããªå
šäœã«å¯ŸããŠå®è¡ããããå€æŽç¹ã®æŠèŠãèŠããªã`diff -r tree1 tree2 | diffstat`ã`vimdiff`ã§ã¯ãã¡ã€ã«ã®æ¯èŒãšç·šéãå¯èœã
|
||
|
||
- ãã€ããªãã¡ã€ã«ãªããåçŽãª16é²ãã³ããèŠãã®ã«`hd`ããã€ããªãšãã£ã¿ã«ã¯`bvi`ã
|
||
|
||
- åãããã€ããªãã¡ã€ã«ã«é¢ããŠãããã¹ããæœåºããããªã`strings`(ãš`grep`ãªã©ã®çµã¿åãã)ã
|
||
|
||
- ãã€ããªã®diff(ãã«ã¿å§çž®)ãªãã`xdelta3`ã
|
||
|
||
- ããã¹ããšã³ã³ãŒãã£ã³ã°ã®å€æã¯`iconv`ã䜿ããããããã¯ããé«åºŠãªããŒã«ãšããŠ`uconv`ãããããã¡ãã¯Unicodeã®é«åºŠãªåŠçãå¯èœãäŸãã°ä»¥äžã®ã³ãã³ãã§ã¯å°æåã«å€æãã¢ã¯ã»ã³ãèšå·ãåãé€ã(å±éããŠããåé€)ã
|
||
|
||
```sh
|
||
uconv -f utf-8 -t utf-8 -x '::Any-Lower; ::Any-NFD; [:Nonspacing Mark:] >; ::Any-NFC; ' < input.txt > output.txt
|
||
```
|
||
|
||
- ãã¡ã€ã«ãåå²ãããªã`split`(ãµã€ãºã§åå²)ãš`csplit`(ãã¿ãŒã³ã§åå²)ã
|
||
|
||
- æ¥æã«ã€ããŠãçŸåšæ¥æãååŸããã«ã¯[ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)ãå©ãã«ãªãã`date -u +"%Y-%m-%dT%H:%M:%SZ"` ã䜿ããã(ä»ã®ãªãã·ã§ã³ã¯[ãã¡ã](https://stackoverflow.com/questions/7216358/date-command-on-os-x-doesnt-have-iso-8601-i-option) [problematic](https://unix.stackexchange.com/questions/164826/date-command-iso-8601-option))ãæ¥ä»ãæéã®è¡šçŸãæ±ãã«ã¯ã[`dateutils`](http://www.fresse.org/dateutils/)ã«ããããã«ã`dateadd`ã `datediff`ã `strptime` ãªã©ã䜿ããŸãããã
|
||
|
||
- å§çž®ãã¡ã€ã«ã®æäœã¯`zless`ã`zmore`ã`zcat`ã`zgrep`ã
|
||
|
||
- `chattr`ã§ãã¡ã€ã«æš©éã«ä»£ããäœéå±€ã®ãã¡ã€ã«å±æ§æ
å ±ãã»ããã§ãããäŸãã°ãæå³ããªããã¡ã€ã«åé€ãé²ããã©ã°ã¯ãããã£ãŠç«ãŠãã`sudo chattr +i /critical/directory/or/file`
|
||
|
||
- ãã¡ã€ã«ã®æš©éãä¿åããªã¹ãã¢ããã«ã¯`getfacl`ãš`setfacl`ã䜿ãããäŸã¯
|
||
```sh
|
||
getfacl -R /some/path > permissions.txt
|
||
setfacl --restore=permissions.txt
|
||
```
|
||
- 空ãã¡ã€ã«ãçŽ æ©ãäœãã«ã¯`truncate`([sparse file](https://en.wikipedia.org/wiki/Sparse_file)ãäœæ)ã`fallocate`(ext4, xfs, btrfs ãšocfs2ãã¡ã€ã«ã·ã¹ãã )ã`xfs_mkfile`(xfsprogs packageã«ããã»ãŒå
šãŠã®ãã¡ã€ã«ã·ã¹ãã )ã`mkfile` (SolarisãMac OSãšãã£ãUnixé¢é£ã·ã¹ãã )
|
||
|
||
## ã·ã¹ãã ã®ãããã°
|
||
|
||
- Webã®ãããã°ãªã`curl`ã`curl -l`ã䟿å©ã§ã`wget`ãåæ§ãããã¢ãã³ãªã®ã¯[`httpie`](https://github.com/jkbrzt/httpie)ã
|
||
|
||
- CPUããã£ã¹ã¯ã®ã¹ããŒã¿ã¹ãç¥ãã«ã¯ãæšæºçãªããŒã«ã¯`top` (ãŸãã¯ãããè¯ã`htop`)ã `iostat`ã `iotop`ã`iostat -mxz 15`ã䜿ã£ãŠãåºæ¬çãªCPUã®æ
å ±ãããŒãã£ãã·ã§ã³åäœã§ã®ãã£ã¹ã¯ã®è©³çŽ°æ
å ±ãããã©ãŒãã³ã¹ã«ã€ããŠèª¿ã¹ãŸãããã
|
||
|
||
- ãããã¯ãŒã¯ã®ç¶æ
ã®ç£èŠã«ã¯ã`netstat`ã`ss`ã
|
||
|
||
- ææ©ãã·ã¹ãã ã§äœãèµ·ããŠããã®ãã調ã¹ãã«ã¯ã`dstat`ã䟿å©ããã詳ããèŠãã«ã¯ã[`glances`](https://github.com/nicolargo/glances)ã
|
||
|
||
- ã¡ã¢ãªã®ã¹ããŒã¿ã¹ãç¥ãã«ã¯ã`free`ãããã¯`vmstat`ãå®è¡ãããã®åºåã®æå³ãç解ããããç¹ã«ã"cached"ã®å€ã¯Linuxã«ãŒãã«ã«ãã¡ã€ã«ãã£ãã·ã¥ãšããŠä¿æãããŠããã¡ã¢ãªéã§ããã"free"ã®å€ãèŠãéã«èæ
®ãã¹ãã§ããããšã«æ³šæãããã
|
||
|
||
- Javaã®ã·ã¹ãã ã®ãããã°ã¯ãŸãéãå°ã£ããšãããããããOracleãããã¯ä»ã®JVMã«ãå
±éããŠããã·ã³ãã«ãªããªãã¯ã¯ã`kill -3 <pid>`ã§ãã«ã¹ã¿ãã¯ãã¬ãŒã¹ãšããŒãã®æŠèŠãæšæºåºåãããã¯ãã°ã«ãã³ãããã(äžä»£å¥GCã®è©³çŽ°ãåèçšåºŠã ãå«ãŸããŠãã)ãJDKã® `jps`ã `jstat`ã `jstack`ã `jmap` ã䟿å©ã§ã[SJK tools](https://github.com/aragozin/jvm-tools)ã¯ããé«åºŠãªããŒã«ã§ããã
|
||
|
||
- æ¹è¯çtracerouteãšããŠ[`mtr`](http://www.bitwizard.nl/mtr/)ã䜿ã£ãŠãããã¯ãŒã¯ã®åé¡ã調æ»ãããã
|
||
|
||
- ãã£ã¹ã¯ããã£ã±ãã«ãªã£ãŠããçç±ã調ã¹ãã«ã¯ã[`ncdu`](https://dev.yorhel.nl/ncdu)ã䜿ããš`du -sh *`ããæéãç¯çŽã§ããã
|
||
|
||
- 垯åã䜿ã£ãŠããã®ãã©ã®ãœã±ãããããã»ã¹ãªã®ããèŠã€ããã«ã¯ã[`iftop`](http://www.ex-parrot.com/~pdw/iftop/)ãããã¯[`nethogs`](https://github.com/raboof/nethogs)ãè©Šããã
|
||
|
||
- `ab`(Apacheã«ä»å±)ã¯ãWebãµãŒãã®ããã©ãŒãã³ã¹ããã£ãããã§ãã¯ããã®ã«äŸ¿å©ãããè€éãªãã¹ãã«ã¯`siege`ãè©Šããã
|
||
|
||
- ãã確å®ãªãããã¯ãŒã¯ã®ãããã°ã¯[`wireshark`](https://wireshark.org/)ã[`tshark`](https://www.wireshark.org/docs/wsug_html_chunked/AppToolstshark.html)ã[`ngrep`](http://ngrep.sourceforge.net/)ã
|
||
|
||
- `strace`ãš`ltrace`ã«ã€ããŠç¥ã£ãŠããããããã°ã©ã ã®å®è¡ã«å€±æããããã³ã°ãããã¯ã©ãã·ã¥ãããããŠããã®çç±ãåãããªãããããã¯ããã©ãŒãã³ã¹ã«é¢ããäžè¬çæ
å ±ãç¥ããããªãããã®ããŒã«ã圹ç«ã€ã¯ãã ããããã¡ã€ãªã³ã°ã®ãªãã·ã§ã³(`-c`)ãèµ·åäžã®ããã»ã¹ã«ã¢ã¿ããããæ©èœ(`-p`)ãèŠããŠãããã
|
||
|
||
- å
±æã©ã€ãã©ãªããã§ãã¯ãããªã`ldd`ãèŠããŠããããã§ã[æªãããã¡ã€ã«ãæå®ããŠå®è¡ããªãããã«](http://www.catonmat.net/blog/ldd-arbitrary-code-execution/)
|
||
|
||
- èµ·åäžã®ããã»ã¹ã«`gdb`ã§æ¥ç¶ãããã®ã¹ã¿ãã¯ãã¬ãŒã¹ãåãæ¹æ³ãç¥ããã
|
||
|
||
- `/proc`以äžã®ãã¡ã€ã«ã䜿ãããä»èµ·ãã£ãŠããåé¡ããããã°ããã®ã«ã¯çŽ æŽããã䟿å©ã ãäŸãã°ã`/proc/cpuinfo`ã`/proc/meminfo`ã`/proc/cmdline`ã`/proc/xxx/cwd`ã`/proc/xxx/ece`ã`/proc/xxx/fd/`ã`/proc/xxx/smaps` (ããã§ã`xxx`ã¯ããã»ã¹IDãŸãã¯PIDãæå³ãã)ã
|
||
|
||
- éå»ã«äœãåé¡ãèµ·ããããšã®åå ãæ¢ããªãã[`sar`](http://sebastien.godard.pagesperso-orange.fr/)ããšãŠã䟿å©ãCPUãã¡ã¢ãªããããã¯ãŒã¯ãªã©ã®éå»ã®çµ±èšæ
å ±ãèŠãããã
|
||
|
||
- ããã«æ·±ãã·ã¹ãã ãšããã©ãŒãã³ã¹ã®åæã«ã¯ã`stap` ([SystemTap](https://sourceware.org/systemtap/wiki))ã[`perf`](https://en.wikipedia.org/wiki/Perf_(Linux))ã
|
||
[`sysdig`](https://github.com/draios/sysdig)ã
|
||
|
||
- ã©ã®OSãå©çšããŠãããã`uname`ã`uname -a` (Unixã«ãŒãã«æ
å ±)ã§ç¢ºèªããããã©ã®ãã£ã¹ããªãã¥ãŒã·ã§ã³ã䜿ã£ãŠãããã¯`lsb_release -a` (ãã£ã¹ããªãã¥ãŒã·ã§ã³æ
å ±)ã
|
||
|
||
- äœããã€ããšéãããããªããš(倧æµããŒããŠã§ã¢ããã©ã€ãé¢é£ã®åé¡ã )ãèµ·ããŠãããã`dmesg`ãå®è¡ãããã
|
||
|
||
- `du`ã§è¡šç€ºããããã£ã¹ã¯ãŒã¹ããŒã¹ããã¡ã€ã«ãæ¶ããŠã空ããªãã£ãå Žåããã®ãã¡ã€ã«ãããã»ã¹ã«äœ¿ãããŠãããã©ãããããã£ãŠç¢ºèªãããã`lsof | grep deleted | grep "filename-of-my-big-file"`
|
||
|
||
## ã¯ã³ã©ã€ããŒ
|
||
|
||
ã³ãã³ãããŸãšããŠäœ¿ãäŸãããã€ãã
|
||
|
||
- `sort`ã`uniq`ã䜿ã£ãŠããã¹ããã¡ã€ã«ã®å
±ééšåãçµåãå·®ç°ãæ±ããæã«ç¹ã«äŸ¿å©ãªã®ã以äžã®ããæ¹ã`a`ãš`b`ã¯ããããå
容ã«éè€ã®ãªãããã¹ããã¡ã€ã«ãšããããã®æ¹æ³ã¯é«éã§ãæ°GBçšåºŠãŸã§ã®ä»»æã®ãã¡ã€ã«ãµã€ãºã§åäœãã(`/tmp`ãå°ããªã«ãŒãããŒãã£ã·ã§ã³ã«ããå Žåã¯`-T`ãªãã·ã§ã³ãã€ããå¿
èŠããããããœãŒãã¯ã¡ã¢ãªå
ã§è¡ããããšã¯éããªã)ãäžè¿°ã®`LC_ALL`ãš`sort`ã®`-u`ãªãã·ã§ã³ãåç
§ã®ããšã
|
||
|
||
```sh
|
||
cat a b | sort | uniq > c # cã¯aãšbã®åéå
|
||
cat a b | sort | uniq -d > c # cã¯aãšbã®å
±ééšå
|
||
cat a b b | sort | uniq -u > c # cã¯aãšbã®å·®ç°
|
||
```
|
||
|
||
- `grep . *`(åè¡ã«ãã¡ã€ã«åãä»ã)ãã`head -100 *` (ãã¡ã€ã«æ¯ã«ããããŒãä»ã)ã䜿ã£ãŠæ軜ã«ãã£ã¬ã¯ããªå
ã®å
šãŠã®ãã¡ã€ã«ã®äžèº«ã確èªã§ãããèšå®ãã¡ã€ã«ãå«ãŸãããããª`/sys`ã`/proc`ã`/etc/`ã«å¯ŸããŠéåžžã«äŸ¿å©ã§ããã
|
||
|
||
- ããã¹ããã¡ã€ã«ã®3åç®ãå
šãŠè¶³ãåãããã«ã¯ä»¥äžã§(Pythonã§åãããšãããã«æ¯ã¹ãŠ3åéã3åã®1ã®é·ãã§æžãã)ã
|
||
|
||
```sh
|
||
awk '{ x += $3 } END { print x }' myfile
|
||
```
|
||
|
||
- ãã¡ã€ã«ããªãŒã®ãµã€ãºãããŒã¿ã確èªããããªãã以äžã¯ååž°çãª`ls -l`ãšåãã ã`ls -lR`ããèŠãããã
|
||
|
||
```sh
|
||
find . -type f -ls
|
||
```
|
||
|
||
- WebãµãŒãã®ãã°ã®ãããªããã¹ããã¡ã€ã«ããããåè¡ã«ã¯äŸãã°URLã®äžã«åºãŠãã`acct_id`ã®ãããªç¹å®ã®å€ãçŸãããšãããã`acct_id`ãäœåãªã¯ãšã¹ããããŠããããéèšããã«ã¯ã
|
||
```sh
|
||
egrep -o 'acct_id=[0-9]+' access.log | cut -d= -f2 | sort | uniq -c | sort -rn
|
||
```
|
||
|
||
- ç¶ç¶çã«å€æŽãç£èŠããå Žå `watch`ã䜿ããäŸãã°ããã£ã¬ã¯ããªã®ãã¡ã€ã«ã®å€æŽã確èªããã«ã¯ `watch -d -n 2 'ls -rtlh | tail'` ãšãªããwifièšå®ãªã©ã®ãããã¯ãŒã¯èšå®é¢ä¿ã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã§ã¯ `watch -d -n 2 ifconfig`ã
|
||
|
||
- ãã®ããã¥ã¡ã³ãããã©ã³ãã ã«é
ç®ãæãåºãã«ã¯ä»¥äžã®é¢æ°ãå®è¡ããã(MarkdownãããŒã¹ããã¢ã€ãã ãæœåºãã)ã
|
||
|
||
```sh
|
||
function taocl() {
|
||
curl -s https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md |
|
||
pandoc -f markdown -t html |
|
||
xmlstarlet fo --html --dropdtd |
|
||
xmlstarlet sel -t -v "(html/body/ul/li[count(p)>0])[$RANDOM mod last()+1]" |
|
||
xmlstarlet unesc | fmt -80
|
||
}
|
||
```
|
||
|
||
## ç®ç«ããªãã䟿å©ãªãã®
|
||
|
||
- `expr`: ç®è¡æŒç®ãè«çæŒç®ããŸãã¯æ£èŠè¡šçŸã®è©äŸ¡ãå®è¡
|
||
|
||
- `m4`: ã·ã³ãã«ãªãã¯ãããã»ããµ
|
||
|
||
- `yes`: æååããããã衚瀺
|
||
|
||
- `cal`: ããæãã®ã«ã¬ã³ããŒ
|
||
|
||
- `env`: ã³ãã³ããå®è¡(ã¹ã¯ãªããå
ã§éå®ãã)
|
||
|
||
- `printenv`: ç°å¢å€æ°ã衚瀺ãã(ãããã°ãã¹ã¯ãªããå
ã§ã®äœ¿çšã«äŸ¿å©)
|
||
|
||
- `look`: æååã§å§ãŸãè±åèª(ãŸãã¯ãã¡ã€ã«å
ã®è¡)ãèŠã€ãã
|
||
|
||
- `cut `ã `paste`ã`join`: ããŒã¿ã®æäœ
|
||
|
||
- `fmt`: ããã¹ãã®æ®µèœããã©ãŒããããã
|
||
|
||
- `pr`: ããã¹ããããŒãžãšã«ã©ã ã«ãã©ãŒããããã
|
||
|
||
- `fold`: ããã¹ãã®è¡ãåå²
|
||
|
||
- `column`: ããã¹ããã«ã©ã ãããã¯ããŒãã«ã«ãã©ãŒããã
|
||
|
||
- `expand` ãš `unexpand`: ã¿ããšã¹ããŒã¹ã®çžäºå€æ
|
||
|
||
- `nl`: è¡æ°ã衚瀺
|
||
|
||
- `seq`: æ°åã衚瀺
|
||
|
||
- `bc`: èšç®æ©
|
||
|
||
- `factor`: æŽæ°ãå æ°å解
|
||
|
||
- [`gpg`](https://gnupg.org/): ãã¡ã€ã«ã®æå·åãšçœ²å
|
||
|
||
- `toe`: terminfoã®ãšã³ããªã®ããŒãã«ã衚瀺
|
||
|
||
- `nc`: ãããã¯ãŒã¯ã®ãããã°ãšããŒã¿è»¢é
|
||
|
||
- `socat`: ãœã±ãããªã¬ãŒãšTCPããŒãã®ãã©ã¯ãŒã(`netcat`ãšåç)
|
||
|
||
- [`slurm`](https://github.com/mattthias/slurm): ãããã¯ãŒã¯ãã©ãã£ãã¯ã®å¯èŠå
|
||
|
||
- `dd`: ããŒã¿ããã¡ã€ã«ãããã¯ããã€ã¹éã§ç§»å
|
||
|
||
- `file`: ãã¡ã€ã«ã®çš®é¡ãç¹å®
|
||
|
||
- `tree`: ãã£ã¬ã¯ããªãšãµããã£ã¬ã¯ããªãããªãŒã§è¡šç€ºã`ls`ã«äŒŒãŠãããååž°çã«åã
|
||
|
||
- `stat`: ãã¡ã€ã«ã®æ
å ±
|
||
|
||
- `time`: ã³ãã³ããå®è¡ããŠåŠçæéãèšæž¬
|
||
|
||
- `timeout`: ã³ãã³ããå®è¡ããæå®æéçµéåŸã«ããã»ã¹ãåæ¢ãã
|
||
|
||
- `lockfile`: ã»ããã©ãã¡ã€ã«ãçæãããããã¯`rm -f`ã®ã¿ã§åé€å¯èœã
|
||
|
||
- `logrotate`: ãã°ãããŒããŒããå§çž®ãã¡ãŒã«éä¿¡
|
||
|
||
- `watch`: ã³ãã³ããç¹°ãè¿ãå®è¡ãããå€æŽéšåã®åŒ·èª¿è¡šç€ºãã§ããã
|
||
|
||
- `tac`: ãã¡ã€ã«ãéãã衚瀺
|
||
|
||
- `shuf`: ãã¡ã€ã«ããã©ã³ãã ã«éžãã è¡ã衚瀺
|
||
|
||
- `comm`: ãœãŒãæžã¿ãã¡ã€ã«ã®è¡ãæ¯èŒ
|
||
|
||
- `pv`: ãã€ãçµç±ã§ããŒã¿ã®é²è¡ç¶æ³ãã¢ãã¿ãªã³ã°
|
||
|
||
- `sponge`: æžã蟌ã¿åã«å
šãŠã®å
¥åãèªã¿èŸŒããäŸãã°ã`grep -v something some-file | sponge some-file` ã®ããã«ãå
¥åãšåããã¡ã€ã«ã«æžã蟌ãéã«äŸ¿å©ã
|
||
|
||
- `hd`ã`hexdump`ã`xxd`ã`biew`ã`bvi`: ãã€ããªãã¡ã€ã«ã®ãã³ããšç·šé
|
||
|
||
- `strings`: ãã€ããªãã¡ã€ã«ããããã¹ããæœåº
|
||
|
||
- `tr`: æåã®çœ®ãæããšæäœ
|
||
|
||
- `iconv` ããã㯠`uconv`: æåãšã³ã³ãŒãã£ã³ã°ã®å€æ
|
||
|
||
- `split` ãš `csplit`: ãã¡ã€ã«ãåå²
|
||
|
||
- `units`: åäœã®å€æãšèšç®ã2é±éãããã®ããã³(蚳泚 : é·ãã®åäœ)ãããŸã°ããããšã®ãã¥ãŠã£ãããŸã§( `/usr/share/units/definitions.units`ãåç
§ã®ããš)
|
||
|
||
- `apg`: ã©ã³ãã ãªãã¹ã¯ãŒããçæ
|
||
|
||
- `7z`: å§çž®çã®é«ããã¡ã€ã«å§çž®
|
||
|
||
- `ldd`: åçã©ã€ãã©ãªã®æ
å ±
|
||
|
||
- `nm`: ãªããžã§ã¯ããã¡ã€ã«ããã·ã³ãã«ã衚瀺
|
||
|
||
- `ab`: WebãµãŒãã®ãã³ããŒããŒã¯
|
||
|
||
- `strace`: ã·ã¹ãã ã³ãŒã«ã®ãããã°
|
||
|
||
- [`mtr`](http://www.bitwizard.nl/mtr/): ãããã¯ãŒã¯ãããã°ã®ããã®ããé«æ©èœãªtraceroute
|
||
|
||
- `cssh`: ããžã¥ã¢ã«ãªäžŠåã·ã§ã«
|
||
|
||
- `rsync`: ãã¡ã€ã«ããã©ã«ããSSHçµç±ãŸãã¯ããŒã«ã«ãã¡ã€ã«ã·ã¹ãã å
ã§åæ
|
||
|
||
- [`wireshark`](https://wireshark.org/) ãš [`tshark`](https://www.wireshark.org/docs/wsug_html_chunked/AppToolstshark.html): ãã±ãããã£ããã£ãšãããã¯ãŒã¯ãããã®ã³ã°
|
||
|
||
- [`ngrep`](http://ngrep.sourceforge.net/): ãããã¯ãŒã¯å±€ã®grep
|
||
|
||
- `host` ãš `dig`: DNSåå解決
|
||
|
||
- `lsof`:ããã»ã¹ã®ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãšãœã±ããæ
å ±
|
||
|
||
- `dstat`: 䟿å©ãªã·ã¹ãã æ
å ±
|
||
|
||
- [`glances`](https://github.com/nicolargo/glances): é«ã¬ãã«ã«è€æ°ã®ãµãã·ã¹ãã ã®æŠèŠãææ¡
|
||
|
||
- `iostat`: ãã£ã¹ã¯ã®äœ¿çšç¶æ³
|
||
|
||
- `mpstat`: CPUã®äœ¿çšç¶æ³
|
||
|
||
- `vmstat`: ã¡ã¢ãªã®äœ¿çšç¶æ³
|
||
|
||
- `htop`: topã®æ¹è¯ç
|
||
|
||
- `last`: ãã°ã€ã³å±¥æŽ
|
||
|
||
- `w`: 誰ããã°ã€ã³ããŠããã
|
||
|
||
- `id`: ãŠãŒã¶ãã°ã«ãŒãã®æ
å ±
|
||
|
||
- [`sar`](http://sebastien.godard.pagesperso-orange.fr/): ã·ã¹ãã çµ±èšæ
å ±ã®å±¥æŽ
|
||
|
||
- [`iftop`](http://www.ex-parrot.com/~pdw/iftop/) ãŸã㯠[`nethogs`](https://github.com/raboof/nethogs): ãœã±ãããããã¯ããã»ã¹ããšã®ãããã¯ãŒã¯äœ¿çšé
|
||
|
||
- `ss`: ãœã±ããã®çµ±èšæ
å ±
|
||
|
||
- `dmesg`: èµ·åæãšã·ã¹ãã ã®ãšã©ãŒã¡ãã»ãŒãž
|
||
|
||
- `sysctl`: Linuxã«ãŒãã«ãã©ã¡ãŒã¿ã®ç¢ºèªããã³èšå®
|
||
|
||
- `hdparm`: SATA/ATAãã£ã¹ã¯ã®æäœãããã©ãŒãã³ã¹ç¢ºèª
|
||
|
||
- `lsblk`: ãããã¯ããã€ã¹ã®äžèŠ§ããã£ã¹ã¯ãšãã£ã¹ã¯ããŒãã£ã·ã§ã³ã®ããªãŒãã¥ãŒ
|
||
|
||
- `lshw`ã`lscpu`ã`lspci`ã`lsusb`ã`dmidecode`: CPUãBIOSãRAIDãã°ã©ãã£ãã¯ããã®ä»ããã€ã¹ãªã©ã®ããŒããŠã§ã¢æ
å ±
|
||
|
||
- `lsmod`ã`modinfo`: ã«ãŒãã«ã®ã¢ãžã¥ãŒã«ãªã¹ããšã¢ãžã¥ãŒã«æ
å ±
|
||
|
||
- `fortune`ã `ddate`ã`sl`: ããŒãããŒãããã¯èžæ°æ©é¢è»ãZippyã®åŒçšå¥ãã䟿å©ãã ãšæããã©ããã«ãã
|
||
|
||
## OS Xçšã®ãã®
|
||
|
||
ãããã¯*MacOSçš*ã®é
ç®ã§ãã
|
||
|
||
- ããã±ãŒãžç®¡çã¯`brew` (Homebrew)ã`port` (MacPorts)ã䜿ããäžèšã®å€ãã®ã³ãã³ããMacOSã«ã€ã³ã¹ããŒã«ã§ããã
|
||
|
||
- ã³ãã³ãã®åºåãã¯ãªããããŒãã«ã³ããŒãã`pbcopy`ãšã¯ãªããããŒãããåºåãã`pbpaste`ã
|
||
|
||
- OptionããŒãaltããŒãšããŠMac OSã®ã¿ãŒããã«ã§äœ¿ã(äžè¿°ã®**alt-b**ã**alt-f**ãªã©ã䜿ãå Žå)ã«ã¯ãç°å¢èšå® -> èšå® -> ããŒããŒã ã§ã"ã¡ã¿ããŒãšããŠoptionããŒã䜿çš"ãéžæã
|
||
|
||
- ãã¹ã¯ãããã¢ããªã±ãŒã·ã§ã³ã§ãã¡ã€ã«ãéãã«ã¯ã`open`ã`open -a /Applications/Whatever.app`ã
|
||
|
||
- Spotlight: `mdfind`ã§ãã¡ã€ã«ãæ€çŽ¢ããã¡ã¿ããŒã¿(ç»åãã¡ã€ã«ã®EXIFã®æ
å ±ãªã©)ã`mdls`ã§è¡šç€ºã
|
||
|
||
- Mac OSã¯BSD UnixããŒã¹ã§ãããããå€ãã®ã³ãã³ã(äŸãã°ã`ps`ã`ls`ã`tail`ã`awk`ã`sed`)ã§ã¯ãUnix System VãšGNUããŒã«ã®éãã«åœ±é¿ãããŠãLinuxã®ãã®ãšæ¯ã¹ãŠåŸ®åŠãªéããå€ãå«ãŸããŠãããéãããããã«ã€ããŠã¯ãããã¥ã¢ã«ããŒãžã®ã¿ã€ãã«ã«"BSD General Commands Manual"ãšæžãããŠãããã©ããã§å€æã§ãããå Žåã«ãã£ãŠã¯ãGNUããŒãžã§ã³ãã€ã³ã¹ããŒã«å¯èœã§ãã(äŸãã°ã`gawk`ã`gsed`ã§ãGNUã®awkãšsedã«å¯Ÿå¿)ãã¯ãã¹ãã©ãããã©ãŒã ã®bashã¹ã¯ãªãããæžãå Žåã«ã¯ããã®ãããªã³ãã³ãã¯é¿ãã(Pythonã`perl`ã®å©çšãæ€èš)ãååãªãã¹ããå¿
èŠã§ããã
|
||
|
||
- Mac OSã®ãªãªãŒã¹æ
å ±ãååŸããã«ã¯ã`sw_vers`ã
|
||
|
||
## Windowså°çš
|
||
|
||
ãããã¯*Windowsçš*ã®é
ç®ã§ãã
|
||
|
||
### Windowsäžã§UnixããŒã«ãæã«å
¥ããæ¹æ³
|
||
|
||
- [Cygwin](https://cygwin.com/)ãMicrosoft Windowsã§ã€ã³ã¹ããŒã«ããŠUnixã·ã§ã«ã®åãæã«ãããããã®ããã¥ã¡ã³ãã§èª¬æãããŠãã倧éšåã¯ã³ã£ããç®±ã¿ããã«ç¬åµçã ã
|
||
|
||
- Windows10ã§ããã°[Windows Subsystem for Linux (WSL)](https://msdn.microsoft.com/commandline/wsl/about)ã䜿ãããUnixã³ãã³ãã©ã€ã³ã芪ãã¿ã®ããBashãæäŸããŠãããã
|
||
|
||
- windowsäžã§ãäž»ã«GNUããããããŒããŒã«(GCCãªã©)ã䜿ãããå Žåã[MinGW](http://www.mingw.org/)ã[MSYS](http://www.mingw.org/wiki/msys)ãæ€èšããããbashãgawkãmakeãgrepãæäŸããŠããããMSYSã¯Cygwinãšæ¯ã¹ããšå
šãŠã®æ©èœãæã£ãŠããããã§ã¯ãªããMinGWã¯UnixããŒã«ã®ãã€ãã£ãWindowsããŒããäœæããã®ã«ç¹ã«æå¹ã ã
|
||
|
||
- Windowsé
äžã§Unixã®èŠãç®ãšæäœæãåŸãããäžã€ã®æ¹æ³ã¯[Cash](https://github.com/dthree/cash)ã ãæ¬åœã«éãããUnixã³ãã³ããã³ãã³ãã©ã€ã³ãªãã·ã§ã³ãããã®ç°å¢ã§ã¯å©çšã§ããªãã®ã§æ³šæãå¿
èŠã ã
|
||
|
||
### 䜿ããWindowsã³ãã³ãã©ã€ã³ããŒã«
|
||
- `wmic`ã䜿ã£ãŠåŠã¶ããšã§ãWindowsã·ã¹ãã 管çè
ã¿ã¹ã¯ã®å€§éšåãã³ãã³ãã©ã€ã³ã§èšè¿°ãå®è¡ããããšãã§ããã
|
||
|
||
- `ping`ã`ipconfig`ã`tracert`ã`netstat`ãªã©ã®Windowsåºæã®ã³ãã³ãã©ã€ã³ã䟿å©ã ãšæããã¯ãã ã
|
||
|
||
- `Rundll32`ãå®è¡ããããšã«ãã£ãŠ[䟿å©ãªWindowsã¿ã¹ã¯](http://www.thewindowsclub.com/rundll32-shortcut-commands-windows)ãå©çšããããšãã§ããã
|
||
|
||
### Cygwinã®ç§èš£ãšã³ã
|
||
|
||
- Cygwinã®ããã±ãŒãžãããŒãžã£ãŒã§è¿œå ã®Unixããã°ã©ã ãã€ã³ã¹ããŒã«ãããã
|
||
|
||
- `mintty`ãã³ãã³ãã©ã€ã³ãŠã£ã³ããŠãšããŠäœ¿ãã
|
||
|
||
- `/dev/clipboard`ã§Windowsã®ã¯ãªããããŒãã«ã¢ã¯ã»ã¹ããŠã¿ããã
|
||
|
||
- ç»é²ãããã¢ããªã±ãŒã·ã§ã³ã§ä»»æã®ãã¡ã€ã«ãéãããã«ã¯`cygstart`ãèµ·åãããã
|
||
|
||
- `regtool`ã§Windowsã¬ãžã¹ããªã«ã¢ã¯ã»ã¹ãããã
|
||
|
||
- `C:\`Windowsãã©ã€ãã®ãã¹ã¯Cygwinäžã§ã¯`/cygdrive/c`ãªã®ã§æ³šæãå¿
èŠã ããŸããCygwinã®`/`ã¯Windowsã®`C:\cygwin`ã ã`cygpath`ã䜿ã£ãŠCygwinã¹ã¿ã€ã«ãšWindowsã¹ã¿ã€ã«ã®ãã¹ãåãæ¿ãããããããã¯Windowsããã°ã©ã ãå®è¡ããã¹ã¯ãªããã§ãšãŠãæå¹ã ã
|
||
|
||
## ãããªããªãœãŒã¹
|
||
|
||
- [awesome-shell](https://github.com/alebcay/awesome-shell): ã·ã§ã«ã®ããŒã«ããªãœãŒã¹ã®ãŸãšã
|
||
- [awesome-osx-command-line](https://github.com/herrbischoff/awesome-osx-command-line): ãã詳ããMac OSã®ã³ãã³ãã©ã€ã³ã¬ã€ã
|
||
- [Strict mode](http://redsymbol.net/articles/unofficial-bash-strict-mode/): ããããã·ã§ã«ã¹ã¯ãªãããæžãããã«
|
||
- [shellcheck](https://github.com/koalaman/shellcheck): ã·ã§ã«ã¹ã¯ãªãã(æ¬æ¥ãbash/sh/zshçš)ã®éç解æããŒã«
|
||
- [Filenames and Pathnames in Shell](http://www.dwheeler.com/essays/filenames-in-shell.html): ã·ã§ã«ã¹ã¯ãªããã§ãã¡ã€ã«åãæ£ããæ±ãããã«
|
||
- [Data Science at the Command Line](http://datascienceatthecommandline.com/#tools): åã¿ã€ãã«ã®æžç±ããåŒçšãããŠããããŒã¿ãµã€ãšã³ã¹ã§åœ¹ã«ç«ã€ã³ãã³ããããŒã«
|
||
|
||
## å
責äºé
|
||
|
||
ããäžéšã®äŸå€ã¯ãããŸãããã³ãŒãã¯èª°ã§ãèªããããã«æžãããŠãããåã«ã¯è²¬ä»»ã䌎ããBashã§*ã§ãã*ãããšãã£ãŠããããã¹ãå¿
èŠããããšããæå³ã§ã¯ãªãïŒ ;)
|
||
|
||
## ã©ã€ã»ã³ã¹
|
||
|
||
[![Creative Commons License](https://i.creativecommons.org/l/by-sa/4.0/88x31.png)](http://creativecommons.org/licenses/by-sa/4.0/)
|
||
|
||
ãã®ããã¥ã¡ã³ãã¯[Creative Commons Attribution-ShareAlike 4.0 International Licene](http://creativecommons.org/licenses/by-sa/4.0/)ã§ã©ã€ã»ã³ã¹ãããã
|