人ã®ãªãã¬ã¼ã·ã§ã³ãè¦ã¦ãã¨ããããã¯ã»ããã£ã¦ãããããã§ãããï¼
ã¨ããããã§èªåããã使ãbashã®ä¾¿å©æ©è½ãã¾ã¨ãã¦ã¿ã¾ããã
1ã¤åã®ä½æ¥ãã£ã¬ã¯ããªã«æ»ã
cd -ã§æ»ãã¾ãã
[mikeda@test01 tmp]$ cd [mikeda@test01 ~]$ cd - [mikeda@test01 tmp]$
pushdãpopdã使ãã°2ã¤åã§ã3ã¤åã§ãæ»ããã®ã§ãããããã©ããªã®ã§åºæ¬ã³ã¬ã ã使ã£ã¦ã¾ãã
ã³ãã³ãã©ã¤ã³ã移åãã
ãã®ç¶æ
ãã
Ctrl+aãå
¥åããã¨ããã³ãããå
é ã«ç§»åãã¾ãã
Ctrl+eãå
¥åããã¨æ«å°¾ã«ç§»åã§ãã
Ctrl+wãå
¥åããã¨ç´åã®ã¯ã¼ããåé¤ã§ãã¾ãã
Ctrl+cã§å
¥åããã£ã³ã»ã«ãã¦æ¬¡ã®è¡ã«ç§»ãã¾ãã
èªåããã使ãã®ã¯ãã®4ã¤ã§ãã
ãã¹ããªããã¾ã使ã
ãã¹ããªæ¤ç´¢
Ctrl+rãå ¥åããã¨ãã¹ããªæ¤ç´¢ã¢ã¼ãã«ãªãã¾ã
[mikeda@test01 ~]$ (reverse-i-search)`':
ããã¹ããå ¥åããã¨ãã¹ããªä¸ã§ãããå«ããã®ãåºã¦ãã¾ãã
[mikeda@test01 ~]$ (reverse-i-search)`cat': cat /etc/hosts
Ctrl+rãããã«å
¥åããã°æ¬¡ã
ã¨ãã¹ããªãããã®ã¼ã£ã¦ããã¾ãã
ãã®ã¾ã¾Enterã§å®è¡ãã¦ããããã¡ãã£ã¨ããã£ã¦å®è¡ãã¦ããããã§ãã
ã¾ãã!æååãã§ãã®æååå«ãç´åã®ã³ãã³ããå®è¡ã§ãã¾ãã
[mikeda@test01 ~]$ !cat cat /etc/hosts 127.0.0.1 test01 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.1.10 puppet-m.mikeda.jp
ãã¹ããªçªå·ã§å®è¡
ã!ãã¹ããªçªå·ãã§ãã®ã³ãã³ããå®è¡ã§ãã¾ã
[mikeda@test01 ~]$ history |grep cat 973 cat /etc/hosts 974 cat /etc/passwd [mikeda@test01 ~]$ !974 cat /etc/hosts 127.0.0.1 test01 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.1.10 puppet-m.mikeda.jp
ç´åã®ã³ãã³ãã®æå¾ã®å¼æ°ã使ã
ã!$ãã§åç §ã§ãã¾ãã
[mikeda@test01 ~]$ file /tmp/test.log /tmp/test.log: ASCII text [mikeda@test01 ~]$ cat !$ cat /tmp/test.log test
- ä¸èº«ãcatã§ç¢ºèªãã¦ããviã§ç·¨é
- ãã¡ã¤ã«ãµã¤ãºã確èªãã¦ããå§ç¸®ã解å
ãªã©ã1ã¤ã®ãã¡ã¤ã«ã«é£ç¶ãã¦ãªãã¬ã¼ã·ã§ã³ãè¡ãæ©ä¼ã¯å¤ãã®ã§ããã®ããã便å©ã§ãã
ç´åã®ã³ãã³ãã®å ¨ã¦ã使ã
ã!!ãã§åç
§ã§ãã¾ããã!$ãã«æ¯ã¹ãã¨ä½¿ç¨é »åº¦ã¯è½ã¡ã¾ããã
ãã¼ããã·ã§ã³ã¨ã©ã¼ãªãsudoã¤ãã§åå®è¡ã
[mikeda@test01 ~]$ cat /etc/sudoers cat: /etc/sudoers: 許å¯ãããã¾ãã [mikeda@test01 ~]$ sudo !! sudo cat /etc/sudoers ## Sudoers allows particular users to run various commands as ## the root user, without needing the root password. ...
ç´åã®ã³ãã³ããwatchã§ç¹°ãè¿ãå®è¡ã
[mikeda@test01 ~]$ ls -l /tmp/test.log -rw-rw-r-- 1 mikeda mikeda 5 3æ 11 13:58 /tmp/test.log [mikeda@test01 ~]$ watch !!
ãªã©ã§ãã¾ã«ä½¿ãã¾ãã
ãã¬ã¼ã¹å±é
ã{}ãã§å²ãã æååãbashãããæãã«å±éãã¦ãããæ©è½ã§ãã
[mikeda@test01 ~]$ echo {1..5} 1 2 3 4 5 [mikeda@test01 ~]$ echo /usr/{bin,src} /usr/bin /usr/src
é層çãªãã£ã¬ã¯ããªãä¸æ°ã«ä½ãã¨ã
[mikeda@test01 tmp]$ mkdir -p work{1..3}/{bin,lib,conf} [mikeda@test01 tmp]$ tree . |-- work1 | |-- bin | |-- conf | `-- lib |-- work2 | |-- bin | |-- conf | `-- lib `-- work3 |-- bin |-- conf `-- lib
ããã¯ã¢ãããã¢ã¼ã«ã¤ãã®ä½æã³ãã³ããç°¡ç¥åãããã¨ãã
[mikeda@test01 tmp]$ cp -a work1{,.bak} [mikeda@test01 tmp]$ tar czf work1{.tgz,} [mikeda@test01 tmp]$ ls work1 work1.bak work1.tgz work2 work3
ãã¾ã«ä¾¿å©ã§ãã
ã§ãä¸çªä½¿ãã®ã¯foræã®å¼æ°ã§ããã
foræãwhileæã使ã
ã³ãã³ãã©ã¤ã³ã§ããã使ãã¾ãã
foræã¯ã¯ã¤ã«ãã«ã¼ãã§è¤æ°ãã¡ã¤ã«ã«ä¸æ¬æä½ãï¼ã¤ã®ä½¿ãæ¹ã
for i in *.log;do mv $i /backup/;done
ä¾ãã¤ãã¤ãã§ããï¼ï¼
é£ç¶ããæ°å¤ãæ±ãå ´åã¯ããããä¾ãå¤ãããã§ãã
for ((i=0;$i<10;i++));do echo $i;done for i in `seq 10`;do echo $i;done
èªåã¯ãã¬ã¼ã¹å±éã§æ¸ãã¡ããã®ãPerlã£ã½ãã¦å¥½ãã§ãã
for i in {1..10};do echo $i;done
追å ã§ãæå®ãã¹ãã«æ¬¡ã SSHãã°ã¤ã³ãã¦ããä¾
for i in 192.168.1.{1..3} test-{web,db};do ssh $i;done
whileã¯readã¨çµã¿åããã¦ä½¿ãã®ãã»ã¨ãã©ã§ãã
[mikeda@test03 ~]$ cat hosts.list 192.168.1.51 192.168.1.52 [mikeda@test03 ~]$ while read l;do echo "## $l";ssh -n $l "hostname";done < hosts.list ## 192.168.1.51 test01 ## 192.168.1.52 test02
readã®ä½¿ãæ¹ã¯ãããã工夫ã®ä½å°ãããã¾ãã
# è¤æ°ã®å¤æ°ã§åãåããåºåãæåã¯ç©ºç½æåã§ãããµããã¨æå¾ã®å¤æ°ã«ã¾ã¨ããããã egrep -v '^($|#)' /etc/hosts | while read ip hosts;do echo $ip;done # åºåãæåã¯IFSå¤æ°ã§å¤æ´å¯è½ while IFS=: read user pass uid gid others;do echo $user $uid;done < /etc/passwd
ç¡éã«ã¼ãã¯ãããªæãã§
[mikeda@test01 ~]$ while :;do date;sleep 3;done 2012å¹´ 3æ 11æ¥ æ¥ææ¥ 15:16:07 JST 2012å¹´ 3æ 11æ¥ æ¥ææ¥ 15:16:10 JST 2012å¹´ 3æ 11æ¥ æ¥ææ¥ 15:16:13 JST
while trueã§ãOKã§ããï¼
ã¤ãã§ã«ãâã®IFSã®ä½¿ãæ¹ãããã§ããã
ä¸æçã«å¤æ°ãå¤æ´ãããå ´åã¯åç¬ã§ä»£å
¥æãæ¸ãã®ã§ã¯ãªãã
[mikeda@test03 ~]$ LANG=C [mikeda@test03 ~]$ date Sun Mar 11 15:01:07 JST 2012
ã³ãã³ãã®åã«æ¸ãã¾ãããã
[mikeda@test01 ~]$ LANG=C date Sun Mar 11 14:55:49 JST 2012 [mikeda@test01 ~]$ date 2012å¹´ 3æ 11æ¥ æ¥ææ¥ 14:55:50 JST
ã¸ããªå¯ä½ç¨ãé²ãã¾ãã
çµããã«
ã¿ããªããããããããªãã¯ããã¯ãæã£ã¦ãã¨æãã®ã§ã
ããããªä¾¿å©ãªæ©è½ããããï¼ãã¨ããã®ããã²ããã°æãã¦ä¸ããï¼