[ Languages: English, Español, Italiano, æ¥æ¬èª, íêµìŽ, Português, Ð ÑÑÑкОй, SlovenÅ¡Äina, УкÑаÑÐœÑÑка, äžæ ]
åæã®ã³ããã bb0c38c0899339e836c37eead4a9534b06c56662
- ã¡ã¿æ å ±
- åºæ¬
- æ¥åžžçã«äœ¿ããã®
- ãã¡ã€ã«ãšããŒã¿ã®åŠç
- ã·ã¹ãã ã®ãããã°
- ã¯ã³ã©ã€ããŒ
- ç®ç«ããªãã䟿å©ãªãã®
- ãããªããªãœãŒã¹
- å 責äºé
ã³ãã³ãã©ã€ã³ã§æµããããã«æäœãã§ãããšããããšã¯ã軜ãèŠããããä»äººããç解ãããªãã¹ãã«ã ãšã¿ãªãããããšãããã ãããããããã®ã¹ãã«ã¯ãæããã«ãããåãããããã¯åããããšã³ãžãã¢ãšããŠã®ããªãã®æè»æ§ãçç£æ§ãæ¹åããŠããããã®ã ãããã§ã¯ãLinuxã§ã³ãã³ãã©ã€ã³ã䜿ãäžã§äŸ¿å©ã ãšæã£ãã¡ã¢ãTipsã®æ°ã ãæããŠã¿ãããããã®ã¯åºç€çã ããéåžžã«è©³ãããã®ãæŽç·Žããããã®ãææ§ãªãã®ãããããã®ããŒãžã¯ãããªã«é·ããã®ã§ã¯ãªãããããã«æžããŠããããšã®å šãŠã䜿ã£ããæãåºãããšãã§ããã°ãããªã詳ãããªããã ããã
ããã«æžããŠããããšã®å€ãã¯ãå ã Quoraã«æžãããŠãããã®ãå€ãããç§ããããã£ãšåªãã人ãã¡ãããã«æ¹åæ¡ãåºãããšãã§ããGithubã«çœ®ãã®ãããã®ã§ã¯ãšæã£ã(蚳泚 : åæã¯Githubäžã«ãã)ãééãããã£ãšããããæ¹ããããšããç¹ãããã°ãã€ã·ã¥ãŒãç»é²ããããã«ãªã¯ãšã¹ããéã£ãŠã»ããïŒ(ãã¡ãããã¡ã¿æ å ±ã®é ãæ¢åã®ãã«ãªã¯ãšã¹ããã€ã·ã¥ãŒããŸã確èªããã)
察象 :
- ãã®ã¬ã€ãã¯ãåå¿è åãã§ãçµéšè åãã§ããããå¹ åºã(æžããŠããããšã¯å šãŠéèŠ)ããã€æ確ã§(å€ãã®ã±ãŒã¹ã«å¯ŸããŠå ·äœçãªäŸãä»ãã)ããããŠç°¡æœ(ä»ã®å Žæã§èŠã€ãããããããªéèŠã§ãªãããšãè±ç·ããããšã¯çã)ã§ããããšããŽãŒã«ã«ããŠãããåé ç®ã¯ãå€ãã®å Žé¢ã«ãããŠå¿ é ã§ããããä»ã®æ¹æ³ã«æ¯ã¹ãŠåçã«æéãç¯çŽããŠãããã ããã
- Linuxåãã«æžããŠãããå€ãã¯MacOS(ãããã¯Cygwin)ã§ã䜿ããããå šéšã§ã¯ãªãã
- ã€ã³ã¿ã©ã¯ãã£ããªBashã䜿ãããšãæ³å®ããŠããããå€ãã®é ç®ã¯ä»ã®ã·ã§ã«ãBashã®ã¹ã¯ãªããã§ã䜿ããã ããã
泚æ :
- 1ããŒãžå
ã«åããããã«ãå
容ã«ã¯æé»çã«æžãããŠããããšããããããã§åãããããç¥ã£ããã³ãã³ããåããã°ã詳现ãã©ããã§èª¿ã¹ãããããããã¯ã§ããã ãããæ°ããããã°ã©ã ãã€ã³ã¹ããŒã«ããã«ã¯ã
apt-get
/yum
/dnf
/pacman
/pip
/brew
(ã©ããé©ãããã®)ã䜿ããã - ã³ãã³ãããªãã·ã§ã³ããã€ããå解ããŠç解ããæå©ãã«ãExplainshellã䜿ããã
-
åºæ¬çãªBashãåŠãŒããå®éã®ãšããã
man bash
ã¯çµæ§ç°¡åã«ç解ã§ããããããªã«é·ããªãã®ã§ãããã§äžéãã®ããšã¯åããããã以å€ã®ã·ã§ã«ãããããBashã¯åŒ·åã ããåžžã«äœ¿çšå¯èœã§ãããšããå©ç¹ããã(èªåã®PCã«å ¥ããŠããŸã£ããšèšã£ãŠzshãfishãªã©ã ããåŠãã§ããŸããšãæ¢åã®ãµãŒãã觊ããªããŠã¯ãªããªãæãªã©ã«å¶çŽãåºãŠããŸã)ã -
ããã¹ããšãã£ã¿ã®ã©ããæäœ1ã€ã«ç¿çããããã¿ãŒããã«å ã§é©åœã«ãã®ãæžãã«ããã£ãŠä»ã«å šã代æ¿åããªããšããç¹ã§ãçæ³çã«ã¯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 -sk *
)ããã¡ã€ã«ã·ã¹ãã 管çã«ã€ããŠã¯ãdf
ãmount
ãfdisk
ãmkfs
ãlsblk
ã -
åºæ¬çãªãããã¯ãŒã¯ç®¡çã«ã€ããŠã
ip
ãããã¯ifconfig
ãdig
ã -
æ£èŠè¡šçŸã«ã€ããŠè©³ããç¥ããã
grep
ãegrep
ã®è²ã ãªãã©ã°ãåãããŠã-i
ã-o
ã-A
ã-B
ãšãã£ããªãã·ã§ã³ã¯ç¥ã£ãŠãããŠæã¯ãªãã -
apt-get
ãyum
ãdnf
ãpacman
(ãã£ã¹ããªãã¥ãŒã·ã§ã³ã«ãã£ãŠéã)ãšãã£ãã³ãã³ãã§ããã±ãŒãžãæ¢ãããã€ã³ã¹ããŒã«ããæ¹æ³ãåŠãŒããPythonããŒã¹ã®ã³ãã³ãã©ã€ã³ããŒã«ãã€ã³ã¹ããŒã«ããã®ã«ãpip
ãå¿ èŠã (åŸã«åºãŠããããã€ãã®ã³ãã³ãã¯pip
ã§ã€ã³ã¹ããŒã«ããã®ãäžçªç°¡å)ã
-
Bashã§ã¯ãåŒæ°ãè£å®ããã®ã«ã¿ãã䜿ããã³ãã³ãå±¥æŽããæ€çŽ¢ããã®ã«ctrl-rã䜿ãã
-
Bashã§ã¯ãæåŸã®åèªãåé€ããã®ã«ã¯ctrl-wãè¡é ãŸã§å šãŠåé€ããã«ã¯ctrl-uã䜿ããåèªããšã«ç§»åããã«ã¯alt-bãŸãã¯alt-fãè¡æ«ãŸã§åé€ããã«ã¯ctrl-kãç»é¢ã®ã¯ãªã¢ã¯ctrl-lãBashã«ãããããã©ã«ãã®ããŒå²ãåœãŠãå šãŠèŠãã«ã¯``man readline`ãåç §ãããããåºãŠãããäŸãã°ã**alt-.**ã¯åã®åŒæ°ãé çªã«è¡šç€ºãã**alt-***ã¯ã°ãããå±éããã
-
vi颚ã®ããŒå²ãåœãŠã奜ããªãã
set -o vi
ãå®è¡ãããã -
æè¿å®è¡ããã³ãã³ãã確èªãããªã
history
ãctrl-rã**alt-.**ã§çšã¯è¶³ããã ãããã!$
(çŽåã®åŒæ°)ã!!
(çŽåã®ã³ãã³ã)ãšãã£ãçç¥åœ¢ãããããããã -
åã®ã¯ãŒãã³ã°ãã£ã¬ã¯ããªã«æ»ããªã
cd -
-
éäžãŸã§ã³ãã³ããå ¥åããããã©å¿å€ããããæã¯ãalt-#ãæã€ãšè¡é ã«
#
ãæ¿å ¥ãããã³ã¡ã³ããšããŠå ¥åããã(ctrl-aã#ãenterã§ãåã)ãããã¯åŸã§ã³ãã³ãå±¥æŽããæ€çŽ¢ã§ããã -
xargs
(ãŸãã¯parallel
)ã䜿ãããéåžžã«åŒ·åãè¡ããšã«ããã€ã®ã¢ã€ãã ãå®è¡ããã(-L
)ãã䞊å床(-P
)ãå¶åŸ¡ã§ãããæ£ããå®è¡ããããå®ãã§ãªããªãããŸãxargs echo
ããŠã¿ãã°ããã-I{}
ã䟿å©ãäŸãã°ä»¥äžã®éãã
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
ãåç §ã -
Bashã¹ã¯ãªããã§ã¯ã
set -x
ã§ãããã°åºåãåºãããå¯èœãªãå³æ Œã¢ãŒãã䜿ãããšã©ãŒãèµ·ããã匷å¶çµäºããããset -e
ããããã€ãã®ãšã©ãŒãå³æ Œã«æ±ãããã«set -o pipefail
ã䜿ãã(ããã¯ã¡ãã£ãšåŸ®åŠãã)ãããè€éãªã¹ã¯ãªãããªããtrap
ã䜿ããã -
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
ãåºåã«ã -
ã³ãã³ãã®åºåã
<(some command)
ã®ããã«ããŠãã¡ã€ã«ã®ããã«æ±ãããäŸãã°ãããŒã«ã«ãšãªã¢ãŒãã®ã®/etc/hosts
ãæ¯èŒãããªã以äžã®ããã«ãªãã
diff /etc/hosts <(ssh somehost cat /etc/hosts)
-
cat <<EOF ...
ã®ãããªãBashã®ããã¢ããã¥ã¡ã³ãããç解ãããã -
Bashã§ã¯ã
some-command >logfile 2>&1
ã§æšæºåºåãšæšæºãšã©ãŒåºåã®äž¡æ¹ããªãã€ã¬ã¯ãã§ãããã³ãã³ããæšæºå ¥åã«å¯ŸããŠãã¡ã€ã«ãã³ãã«ãéãã£ã±ãªãã«ããããã°ã€ã³ããŠããã¿ãŒããã«ã«ã²ãã¥ããŠããããã</dev/null
ããã®ãããç¿æ £ã -
16é²ãš10é²ã®ASCIIããŒãã«ãèŠãã®ã«
man ascii
ã䜿ãããäžè¬çãªãšã³ã³ãŒãã«é¢ããæ å ±ã¯ãman unicode
ãman utf-8
ãman latin1
ã䟿å©ã -
ã¹ã¯ãªãŒã³ã®åå²ã«
screen
ãtmux
ã䜿ãããç¹ã«ããªã¢ãŒãã®SSHã»ãã·ã§ã³ããã¿ãããããã¢ã¿ãããçŽãããããã®ã«æå¹ãã»ãã·ã§ã³æ°žç¶åã ãã®ç°¡åãªãã®ãªãdtach
ã -
SSHã§
-L
ãããã¯-D
(ãŸãã«-R
)ã䜿ã£ãããŒããã³ãã«ã®ããæ¹ãèŠããŠãããšäŸ¿å©ãäŸãã°ãªã¢ãŒãã®ãµãŒããããŠã§ããµã€ãã«ã¢ã¯ã»ã¹ããæãªã©ã -
SSHã®èšå®ãå°ãã§ãæé©åããŠãããšäŸ¿å©ãäŸãã°ä»¥äžã®èšå®ã ãšããããã¯ãŒã¯ç°å¢ã«ããæ¥ç¶æãåé¿ããå§çž®ã䜿çšã(垯åã®çŽ°ãåç·ã䜿ã£ãscpãªã©ã§äŸ¿å©)ãããŒã«ã«ã®å¶åŸ¡ãã¡ã€ã«ãæå®ããŠåäžãµãŒããšã®ãã£ãã«ãå€éåããã
TCPKeepAlive=yes
ServerAliveInterval=15
ServerAliveCountMax=6
Compression=yes
ControlMaster auto
ControlPath /tmp/%r@%h:%p
ControlPersist yes
-
ãã以å€ã®SSHãªãã·ã§ã³ã¯ã»ãã¥ãªãã£äžã®åé¡ãããå¯èœæ§ããããããæå¹ã«ããã«ã¯ããµããããããšããã¹ãããšã«æå®ããããä¿¡é Œã§ãããããã¯ãŒã¯å ã§ã®ã¿äœ¿çšãããªã©æ³šæãå¿ èŠã
StrictHostKeyChecking=no
ãForwardAgent=yes
ãªã©ã -
8é²æ°è¡šçŸã®ãã¡ã€ã«ããŒããã·ã§ã³ã¯ãã·ã¹ãã èšå®ã®éã«äŸ¿å©ã ã
ls
ã®çµæã«ãåºãŠãããééããããã以äžã®ããã«ããŠååŸã§ããã
stat -c '%A %a %n' /etc/timezone
-
äœããã®ã³ãã³ãã®åºåãããã€ã³ã¿ã©ã¯ãã£ãã«å€ãéžæãããå Žåã¯ã
percol
ã䜿ããã -
(gitã䜿ããªã©)äœããã®ã³ãã³ãã®åºåãããã¡ã€ã«ã«é¢ããããåããããå Žåã¯ã
fpp
(PathPicker)ã䜿ããã -
ã«ã¬ã³ããã£ã¬ã¯ããª(ãšãµããã£ã¬ã¯ããª)å šäœãããããã¯ãŒã¯å ã«å ¬éãããWebãµãŒãã«ãããªãã
python -m SimpleHTTPServer 7777
(ããŒã7777ã§å ¬éãPython 2ã®å Žå)ãããã¯python -m http.server 7777
(Python 3ã®å Žå)ã
-
ã«ã¬ã³ããã£ã¬ã¯ããªä»¥äžã®ãã¡ã€ã«ããã¡ã€ã«åã§æ¢ããããªãã
find . -iname '*something*'
ãå Žæãæå®ããã«ãã¡ã€ã«åã§æ€çŽ¢ããããªããlocate something
ãã€ããã(ãã ãupdatedb
ã¯æè¿äœããããã¡ã€ã«ã¯ã€ã³ããã¯ã¹ããŠããªãã§ãããããšã«æ³šæ)ã -
ãœãŒã¹ãããŒã¿ãã¡ã€ã«ã®(
grep -r
ãããé«åºŠãª)äžè¬çãªæ€çŽ¢ã«ã¯ãag
ã䜿ããã -
HTMLãããã¹ãã«å€æãããªãã
lynx -dump -stdin
ã -
MarkdownãHTMLãªã©æ§ã ãªçš®é¡ã®ããã¥ã¡ã³ãã®å€æã«ã¯ã
pandoc
ãè©ŠããŠã¿ããšããã -
XMLãæ±ããªããŠã¯ãªããªããªãã
xmlstartlet
ã¯å€ããããããŒã«ã ã -
JSONã«ã¯
jq
ã䜿ããã -
ExcelãCSVãã¡ã€ã«ã«ã¯ãcsvkitã§
in2csv
ãcsvcut
ãcsvjoin
ãcsvgrep
ãªã©ã䜿ããããã«ãªãã -
Amazon S3ã«ã¯ã
s3cmd
ã䟿å©ã§ãs4cmd
ã¯ããã«é«éãAWSé¢é£ã®åŠçã«ã¯Amazonå ¬åŒã®aws
ãæ¬ ãããªãã -
sort
ãuniq
ãããã«uniqã®-u
ã-d
ãªãã·ã§ã³ãç¥ã£ãŠããããåŸã«åºãŠããã¯ã³ã©ã€ããŒãåç §ãcomm
ã確èªããŠãããã -
è€æ°ã®ããã¹ããã¡ã€ã«ãæäœããã®ã«ã¯ã
cut
ãšpaste
ãjoin
ã¯ç¥ã£ãŠããããcut
ã¯ã¿ããªäœ¿ã£ãŠããããjoin
ã¯å¿ããããŠããã -
wc
ãç解ããæ¹è¡(-l
)ãæå(-m
)ãåèª(-w
)ããã€ã(-c
)ããããã®æ°ãæ¹ãç¥ã£ãŠãããã -
æšæºå ¥åããã¡ã€ã«ãšæšæºåºåã®äž¡æ¹ã«åºã
tee
ãç解ããããls -al | tee file.txt
ã®ããã«äœ¿ãã -
ãã±ãŒã«ã¯ããœãŒãã®é åº(ç §åé åº)ãããã©ãŒãã³ã¹ãªã©ãããããã®ã³ãã³ãã©ã€ã³ããŒã«ã«åŸ®åŠãªãšããã§åœ±é¿ããããšãèŠããŠããããå€ãã®Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³ã§ã¯ã
LANG
ãä»ã®ãã±ãŒã«å€æ°ã¯US Englishã®ãããªããŒã«ã«ãªèšå®ã«ãªã£ãŠããããã±ãŒã«ãå€æŽãããšãœãŒãé åºãå€ããããšã«æ³šæãããããŸããåœéå(i18n)察å¿ã®ã«ãŒãã³ã¯ãœãŒãããã®ä»ã®åŠçãäœåãé ãå®è¡ããããã«ãªãç¹ãç¥ã£ãŠããããå Žå(èšå®ã®åŠçãäžææ§ãèŠã€ããåŠçãªã©)ã«ãã£ãŠã¯ãexport LC_ALL=C
ãšããŠããŸãé ãi18n察å¿ã®åŠçãå®å šã«ç¡èŠããŠããŸãããšãå¯èœã ã -
åçŽãªããŒã¿å å·¥ã®ããã«
awk
ãšsed
ã®åºç€ã身ã«ã€ããããäŸãã°ãããã¹ããã¡ã€ã«ã®3ã«ã©ã ç®ã®åèšãåºããªããawk '{ x += $3 } END { print x }'
ãããã¯ãPythonã§åãããšããããã3åéããã€3åã®1ã®é·ãã§æžããã -
1ã€ãããã¯è€æ°ã®ãã¡ã€ã«å ã®æååãçŽæ¥çœ®ãæããŠããŸãã«ã¯ã
perl -pi.bak -e 's/old-string/new-string/g' my-files-*.txt
- ãã¿ãŒã³ã«ãããã£ãŠããããã®ãã¡ã€ã«åãæžãæããã«ã¯
rename
ã䜿ãããè€éãªãã¡ã€ã«åå€æŽãªãrepren
ã䟿å©ã ã
# ããã¯ã¢ãããã¡ã€ã«foo.bakãfooã«æ»ã
rename 's/\.bak$//' *.bak
# ãã¡ã€ã«åããã£ã¬ã¯ããªåããã¡ã€ã«ã®äžèº«å
šãŠã®fooãbarã«çœ®ãæãã
repren --full --preserve-case --from foo --to bar .
-
ãã¡ã€ã«ããã©ã³ãã ãªè¡ãæãåºãã«ã¯
shuf
-
sort
ã®ãªãã·ã§ã³ãç解ããããããŒãã©ã®ããã«åŠçãããã®ã(-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ã®çµ±èšæ å ±ãèŠããªãdiffstat
ãåç §ããããdiff -r
ã ãšããã£ã¬ã¯ããªå šäœã«å¯ŸããŠå®è¡ããããå€æŽç¹ã®æŠèŠãèŠããªãdiff -r tree1 tree2 | diffstat
ã -
ãã€ããªãã¡ã€ã«ãªããåçŽãª16é²ãã³ããèŠãã®ã«
hd
ããã€ããªãšãã£ã¿ã«ã¯bvi
ã -
åãããã€ããªãã¡ã€ã«ã«é¢ããŠãããã¹ããæœåºããããªã
strings
(ãšgrep
ãªã©ã®çµã¿åãã)ã -
ãã€ããªã®diff(ãã«ã¿å§çž®)ãªãã
xdelta3
ã -
ããã¹ããšã³ã³ãŒãã£ã³ã°ã®å€æã¯
iconv
ã䜿ããããããã¯ããé«åºŠãªããŒã«ãšããŠuconv
ãããããã¡ãã¯Unicodeã®é«åºŠãªåŠçãå¯èœãäŸãã°ä»¥äžã®ã³ãã³ãã§ã¯å°æåã«å€æãã¢ã¯ã»ã³ãèšå·ãåãé€ã(å±éããŠããåé€)ã
uconv -f utf-8 -t utf-8 -x '::Any-Lower; ::Any-NFD; [:Nonspacing Mark:] >; ::Any-NFC; ' < input.txt > output.txt
-
ãã¡ã€ã«ãåå²ãããªã
split
(ãµã€ãºã§åå²)ãšcsplit
(ãã¿ãŒã³ã§åå²)ã -
å§çž®ãã¡ã€ã«ã®æäœã¯
zless
ãzmore
ãzcat
ãzgrep
ã
-
Webã®ãããã°ãªã
curl
ãcurl -l
ã䟿å©ã§ãwget
ãåæ§ãããã¢ãã³ãªã®ã¯httpie
ã -
ãã£ã¹ã¯ãCPUããããã¯ãŒã¯ã®ã¹ããŒã¿ã¹ãç¥ãã«ã¯
iostat
ãnetstat
ãtop
(ãããã¯htop
ã®æ¹ããã)ã(äžçªã¯)dstat
ãã·ã¹ãã ã§äœãèµ·ããŠããã®ãçŽ æ©ãç¥ãã«ã¯ããã -
æŽã«è©³ããã·ã¹ãã ã®å šäœåãèŠãã«ã¯ã
glances
ã䜿ãããã²ãšã€ã®ã¿ãŒããã«å ã§ãããã€ãã®ã·ã¹ãã ã¬ãã«ã®çµ±èšæ å ±ã衚瀺ããŠããããè€æ°ã®ãµãã·ã¹ãã ãçŽ æ©ããã§ãã¯ããã®ã«éåžžã«äŸ¿å©ã -
ã¡ã¢ãªã®ã¹ããŒã¿ã¹ãç¥ãã«ã¯ã
free
ãããã¯vmstat
ãå®è¡ãããã®åºåã®æå³ãç解ããããç¹ã«ã"cached"ã®å€ã¯Linuxã«ãŒãã«ã«ãã¡ã€ã«ãã£ãã·ã¥ãšããŠä¿æãããŠããã¡ã¢ãªéã§ããã"free"ã®å€ãèŠãéã«èæ ®ãã¹ãã§ããããšã«æ³šæãããã -
Javaã®ã·ã¹ãã ã®ãããã°ã¯ãŸãéãå°ã£ããšãããããããOracleãããã¯ä»ã®JVMã«ãå ±éããŠããã·ã³ãã«ãªããªãã¯ã¯ã
kill -3 <pid>
ã§ãã«ã¹ã¿ãã¯ãã¬ãŒã¹ãšããŒãã®æŠèŠãæšæºåºåãããã¯ãã°ã«ãã³ãããã(äžä»£å¥GCã®è©³çŽ°ãåèçšåºŠã ãå«ãŸããŠãã)ã -
æ¹è¯çtracerouteãšããŠ
mtr
ã䜿ã£ãŠãããã¯ãŒã¯ã®åé¡ã調æ»ãããã -
ãã£ã¹ã¯ããã£ã±ãã«ãªã£ãŠããçç±ã調ã¹ãã«ã¯ã
ncdu
ã䜿ããšdu -sh *
ããæéãç¯çŽã§ããã -
垯åã䜿ã£ãŠããã®ãã©ã®ãœã±ãããããã»ã¹ãªã®ããèŠã€ããã«ã¯ã
iftop
ãããã¯nethogs
ãè©Šããã -
ab
(Apacheã«ä»å±)ã¯ãWebãµãŒãã®ããã©ãŒãã³ã¹ããã£ãããã§ãã¯ããã®ã«äŸ¿å©ãããè€éãªãã¹ãã«ã¯siege
ãè©Šããã -
ãã確å®ãªãããã¯ãŒã¯ã®ãããã°ã¯
wireshark
ãtshark
ãngrep
ã -
strace
ãšltrace
ã«ã€ããŠç¥ã£ãŠããããããã°ã©ã ã®å®è¡ã«å€±æããããã³ã°ãããã¯ã©ãã·ã¥ãããããŠããã®çç±ãåãããªãããããã¯ããã©ãŒãã³ã¹ã«é¢ããäžè¬çæ å ±ãç¥ããããªãããã®ããŒã«ã圹ç«ã€ã¯ãã ããããã¡ã€ãªã³ã°ã®ãªãã·ã§ã³(-c
)ãèµ·åäžã®ããã»ã¹ã«ã¢ã¿ããããæ©èœ(-p
)ãèŠããŠãããã -
å ±æã©ã€ãã©ãªããã§ãã¯ãããªã
ldd
ãèŠããŠãããã -
èµ·åäžã®ããã»ã¹ã«
gdb
ã§æ¥ç¶ãããã®ã¹ã¿ãã¯ãã¬ãŒã¹ãåãæ¹æ³ãç¥ããã -
/proc
以äžã®ãã¡ã€ã«ã䜿ãããä»èµ·ãã£ãŠããåé¡ããããã°ããã®ã«ã¯çŽ æŽããã䟿å©ã ãäŸãã°ã/proc/cpuinfo
ã/proc/xxx/cwd
ã/proc/xxx/ece
ã/proc/xxx/fd/
ã/proc/xxx/smaps
ã -
éå»ã«äœãåé¡ãèµ·ããããšã®åå ãæ¢ããªãã
sar
ããšãŠã䟿å©ãCPUãã¡ã¢ãªããããã¯ãŒã¯ãªã©ã®éå»ã®çµ±èšæ å ±ãèŠãããã -
ããã«æ·±ãã·ã¹ãã ãšããã©ãŒãã³ã¹ã®åæã«ã¯ã
stap
(SystemTap)ãperf
ãsysdig
ã -
ã©ã®ãã£ã¹ããªãã¥ãŒã·ã§ã³ã䜿ã£ãŠããã確èªããããå€ãã®ãã£ã¹ããªãã¥ãŒã·ã§ã³ã§ã¯
lsb_release -a
-
äœããã€ããšéãããããªããš(倧æµããŒããŠã§ã¢ããã©ã€ãé¢é£ã®åé¡ã )ãèµ·ããŠãããã
dmesg
ãå®è¡ãããã
ã³ãã³ãããŸãšããŠäœ¿ãäŸãããã€ãã
sort
ãuniq
ã䜿ã£ãŠããã¹ããã¡ã€ã«ã®å ±ééšåãçµåãå·®ç°ãæ±ããæã«ç¹ã«äŸ¿å©ãªã®ã以äžã®ããæ¹ãa
ãšb
ã¯ããããå 容ã«éè€ã®ãªãããã¹ããã¡ã€ã«ãšããããã®æ¹æ³ã¯é«éã§ãæ°GBçšåºŠãŸã§ã®ä»»æã®ãã¡ã€ã«ãµã€ãºã§åäœãã(/tmp
ãå°ããªã«ãŒãããŒãã£ã·ã§ã³ã«ããå Žåã¯-T
ãªãã·ã§ã³ãã€ããå¿ èŠããããããœãŒãã¯ã¡ã¢ãªå ã§è¡ããããšã¯éããªã)ãäžè¿°ã®LC_ALL
ãšsort
ã®-u
ãªãã·ã§ã³ãåç §ã®ããšã
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ã®å·®ç°
-
ã³ã³ãã£ã°ãå«ãŸããŠãã
/sys
ã/proc
ã/etc/
ã®ãããªãã£ã¬ã¯ããªå ã®å šãŠã®ãã¡ã€ã«ã®äžèº«å šéšã確èªããã«ã¯grep . *
ã䜿ããã -
ããã¹ããã¡ã€ã«ã®3åç®ãå šãŠè¶³ãåãããã«ã¯ä»¥äžã§(Pythonã§åãããšãããã«æ¯ã¹ãŠ3åéã3åã®1ã®é·ãã§æžãã)ã
awk '{ x += $3 } END { print x }' myfile
- ãã¡ã€ã«ããªãŒã®ãµã€ãºãããŒã¿ã確èªããããªãã以äžã¯ååž°çãª
ls -l
ãšåãã ãls -lR
ããèŠãããã
find . -type f -ls
- äºæ
ãèš±ããªã
xargs
ãparallel
ã䜿ãããè¡ãããããã€ã®ã¢ã€ãã ãå®è¡ããã(-L
)ã䞊å床(-P
)ã¯å¶åŸ¡ã§ããã®ã«ã泚æãæ£ãã䜿ããŠãããå¿é ãªæã«ã¯ãxargs echoããŸããã£ãŠã¿ããããŸãã-I{}
ã䟿å©ã ã以äžã®äŸãã¿ãŠã¿ããã
find . -name '*.py' | xargs grep some_function
cat hosts | xargs -I{} ssh root@{} hostname
- WebãµãŒãã®ãã°ã®ãããªããã¹ããã¡ã€ã«ããããåè¡ã«ã¯äŸãã°URLã®äžã«åºãŠãã
acct_id
ã®ãããªç¹å®ã®å€ãçŸãããšããããacct_id
ãäœåãªã¯ãšã¹ããããŠããããéèšããã«ã¯ã
cat access.log | egrep -o 'acct_id=[0-9]+' | cut -d= -f2 | sort | uniq -c | sort -rn
- ãã®ããã¥ã¡ã³ãããã©ã³ãã ã«é ç®ãæãåºãã«ã¯ä»¥äžã®é¢æ°ãå®è¡ããã(MarkdownãããŒã¹ããã¢ã€ãã ãæœåºãã)ã
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
: æå·åãšãã¡ã€ã«ã®ãµã€ãã³ã° -
toe
: terminfoã®ãšã³ããªã®ããŒãã«ã衚瀺 -
nc
: ãããã¯ãŒã¯ã®ãããã°ãšããŒã¿è»¢é -
socat
: ãœã±ãããªã¬ãŒãšTCPããŒãã®ãã©ã¯ãŒã(netcat
ãšåç) -
slurm
: ãããã¯ãŒã¯ãã©ãã£ãã¯ã®å¯èŠå -
dd
: ããŒã¿ããã¡ã€ã«ãããã¯ããã€ã¹éã§ç§»å -
file
: ãã¡ã€ã«ã®çš®é¡ãç¹å® -
tree
: ãã£ã¬ã¯ããªãšãµããã£ã¬ã¯ããªãããªãŒã§è¡šç€ºãls
ã«äŒŒãŠãããååž°çã«åã -
stat
: ãã¡ã€ã«ã®æ å ± -
tac
: ãã¡ã€ã«ãéãã衚瀺 -
shuf
: ãã¡ã€ã«ããã©ã³ãã ã«éžãã è¡ã衚瀺 -
comm
: ãœãŒãæžã¿ãã¡ã€ã«ã®è¡ãæ¯èŒ -
pv
: ãã€ãçµç±ã§ããŒã¿ã®é²è¡ç¶æ³ãã¢ãã¿ãªã³ã° -
hd
ããã³bvi
: ãã€ããªãã¡ã€ã«ã®ãã³ããšç·šé -
strings
: ãã€ããªãã¡ã€ã«ããããã¹ããæœåº -
tr
: æåã®çœ®ãæããšæäœ -
iconv
ãããã¯uconv
: æåãšã³ã³ãŒãã£ã³ã°ã®å€æ -
split
ãšcsplit
: ãã¡ã€ã«ãåå² -
units
: åäœã®å€æãšèšç®ã2é±éãããã®ããã³(蚳泚 : é·ãã®åäœ)ãããŸã°ããããšã®ãã¥ãŠã£ãããŸã§(/usr/share/units/definitions.units
ãåç §ã®ããš) -
7z
: å§çž®çã®é«ããã¡ã€ã«å§çž® -
ldd
: åçã©ã€ãã©ãªã®æ å ± -
nm
: ãªããžã§ã¯ããã¡ã€ã«ããã·ã³ãã«ã衚瀺 -
ab
: WebãµãŒãã®ãã³ããŒããŒã¯ -
strace
: ã·ã¹ãã ã³ãŒã«ã®ãããã° -
mtr
: ãããã¯ãŒã¯ãããã°ã®ããã®ããé«æ©èœãªtraceroute -
cssh
: ããžã¥ã¢ã«ãªäžŠåã·ã§ã« -
rsync
: ãã¡ã€ã«ããã©ã«ããSSHçµç±ã§åæ -
wireshark
ãštshark
: ãã±ãããã£ããã£ãšãããã¯ãŒã¯ãããã®ã³ã° -
ngrep
: ãããã¯ãŒã¯å±€ã®grep -
host
ãšdig
: DNSåå解決 -
lsof
:ããã»ã¹ã®ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãšãœã±ããæ å ± -
dstat
: 䟿å©ãªã·ã¹ãã æ å ± -
glances
: é«ã¬ãã«ã«è€æ°ã®ãµãã·ã¹ãã ã®æŠèŠãææ¡ -
iostat
: CPUãšãã£ã¹ã¯ã®äœ¿çšç¶æ³ -
htop
: topã®æ¹è¯ç -
last
: ãã°ã€ã³å±¥æŽ -
w
: 誰ããã°ã€ã³ããŠããã -
id
: ãŠãŒã¶ãã°ã«ãŒãã®æ å ± -
sar
: ã·ã¹ãã çµ±èšæ å ±ã®å±¥æŽ -
iftop
ãŸãã¯nethogs
: ãœã±ãããããã¯ããã»ã¹ããšã®ãããã¯ãŒã¯äœ¿çšé -
ss
: ãœã±ããã®çµ±èšæ å ± -
dmesg
: èµ·åæãšã·ã¹ãã ã®ãšã©ãŒã¡ãã»ãŒãž -
hdparm
: SATA/ATAãã£ã¹ã¯ã®æäœãããã©ãŒãã³ã¹ç¢ºèª -
lsb_release
: Linuxãã£ã¹ããªãã¥ãŒã·ã§ã³æ å ± -
lsblk
: ãããã¯ããã€ã¹ã®äžèŠ§ããã£ã¹ã¯ãšãã£ã¹ã¯ããŒãã£ã·ã§ã³ã®ããªãŒãã¥ãŒ -
lshw
ãšlspci
: RAIDãã°ã©ãã£ãã¯ãªã©ãå«ããããŒããŠã§ã¢æ å ± -
fortune
ãddate
ãsl
: ããŒãããŒãããã¯èžæ°æ©é¢è»ãZippyã®åŒçšå¥ãã䟿å©ãã ãšæããã©ããã«ãã
- awesome-shell: ã·ã§ã«ã®ããŒã«ããªãœãŒã¹ã®ãŸãšã
- ããããã·ã§ã«ã¹ã¯ãªãããæžãã«ã¯Strict mode
ããäžéšã®äŸå€ã¯ãããŸãããã³ãŒãã¯èª°ã§ãèªããããã«æžãããŠãããåã«ã¯è²¬ä»»ã䌎ããBashã§ã§ãããããšãã£ãŠããããã¹ãå¿ èŠããããšããæå³ã§ã¯ãªãïŒ ;)
ãã®ããã¥ã¡ã³ãã¯Creative Commons Attribution-ShareAlike 4.0 International Liceneã§ã©ã€ã»ã³ã¹ãããã