1581, 3/80 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   ±«µµjs
   II. ÀϹݸí·É¾î2.

http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=208 [º¹»ç]


l          grep : ƯÁ¤ÇÑ ¹®ÀÚ ¶Ç´Â ¹®ÀÚ¿­ Ãâ·Â

l          cat : ÆÄÀÏÀÇ ³»¿ë Ãâ·Â

l          more / less : Å뵶À» À§ÇÑ ÆäÀÌÁö ´ÜÀ§·Î ÇÊÅ͸µÇؼ­ Ãâ·Â

l          head / tail : ÆÄÀÏÀÇ ³»¿ë Ãâ·Â

l          Ç¥ÁØ ÀÔÃâ·Â

l          ÀÔÃâ·Â ÀçÁöÁ¤ (Redirection)

l          ÆÄÀÌÇÁ

l          find / locate : ÆÄÀÏ ¶Ç´Â µð·ºÅ丮 °Ë»ö

l          which / whereis

l          df : ÆÄƼ¼Ç Á¤º¸ º¸±â

l          du : µð·ºÅ丮 »ç¿ë·® º¸±â

l          Á¤±ÔÇ¥Çö½Ä

grep

ÁÖ¾îÁø patternÀ» Æ÷ÇÔÇÏ´Â fileÀÇ line Ãâ·ÂÇÏ´Â ¸í·É¾îÀÌ´Ù. ³ªÁß¿¡ ¹è¿ï ÆÄÀÌÇÁ(|)¿Í ¿¬°áµÇ¾î ¸¹ÀÌ ¾²ÀÌ´Â ¸í·ÉÀÌ´Ù.

ÁÖ¿ä ¿É¼Ç

  ¨ç -i : ignore. Á¶»çÇÒ ÆÐÅÏÀÇ ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏÁö ¾ÊÀ½.

  ¨è -n : number. pattern°ú ÀÏÄ¡ÇÏ´Â ³»¿ëÀ» °¡Áø ¶óÀÎ ¹øÈ£ Ãâ·Â

  ¨é -w : word. ÇѴܾî·Î Á¤È®ÇÏ°Ô ÀÏÄ¡ÇÏ´Â ´Ü¾î°¡ ÀÖ´Â °æ¿ì¿¡ Ãâ·Â

¿¹)

[root@www /root]# grep mk /etc/passwd

mk:x:500:500::/home/mk:/bin/bash

[root@www /root]# ps -aux |grep sendmail

root      9250  0.0  0.7  5008 1876 ?        S    Mar02   0:00 sendmail: accepti

root     31109  0.0  0.2  1624  616 pts/1    S    21:01   0:00 grep sendmail

[root@www /root]# rpm -qa |grep sendmail

sendmail-cf-8.11.3-1wl

sendmail-8.11.3-1wl


cat

fileÀÇ ¸ðµç ³»¿ëÀ» Ãâ·ÂÇÑ´Ù. ÆíÁýÀ» ÇÏ°í ½ÍÀ» °æ¿ì´Â vi³ª pico¸¦ ÀÌ¿ëÇØ¾ß ÇÑ´Ù.

ÁÖ¿ä ¿É¼Ç

-n' ¿É¼Ç : ¸ðµç Ãâ·ÂÇàÀÇ °³¼ö¸¦ Ãâ·ÂÇÑ´Ù.

¿¹)

[root@www /root]# cat  /etc/inittab


more

ÆäÀÌÁö ´ÜÀ§·Î ÇÊÅ͸µÇؼ­ Ãâ·Â À̶§, È­¸é ÇÏ´Ü¿¡ %·Î ÇöÀç Ç¥½Ã·®À» º¸¿©ÁØ´Ù.

b(backward) ¿Í f(forward) Å°¸¦ ÀÌ¿ëÇؼ­ È­¸é À§ ¾Æ·¡·Î ½ºÅ©·Ñ °¡´ÉÇϸç, qÅ°¸¦ Ä¡¸é(quit) ºüÁ®³ª°£´Ù.

¿¹)

[root@www /root]# more  /etc/inittab

less

more¿Í ºñ½ÁÇÏÁö¸¸ Á» ´õ ´Ù¾çÇÑ ±â´ÉÀ» Á¦°øÇϸç, bÅ°¿Í f¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ã±â ±â´Éµµ Á¦°øÇÑ´Ù. qÅ°¸¦ Ä¡¸é(quit) ºüÁ®³ª°£´Ù.

¿¹)

[root@www /root]# less  /etc/inittab


head

À§·ÎºÎÅÍ »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ ¶óÀμö ¸¸Å­ º¸¿©ÁØ´Ù. default´Â 10ÁÙÀÌ´Ù.

¿¹)

[root@www /root]# head -3 /etc/passwd

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:

daemon:x:2:2:daemon:/sbin:

tail

¾Æ·¡·ÎºÎÅÍ »ç¿ëÀÚ°¡ ÁöÁ¤ÇÑ ¶óÀμö ¸¸Å­ º¸¿©ÁØ´Ù. log-file º¼ ¶§ –f ¿É¼ÇÀ» ÀÌ¿ëÇÏ¿© ½Ç½Ã°£À¸·Î ·Î±×¸¦ ¸ð´ÏÅ͸µ ÇÒ ¼ö ÀÖ´Ù.

¿¹)

[root@www /root]# tail -3 /var/log/secure

Mar  7 20:07:02 www proftpd[30969]: www.mk.com (127.0.0.1[127.0.0.1]) - USER mk (Login failed): Incorrect password.

Mar  7 20:07:07 www proftpd[30971]: www.mk.com (127.0.0.1[127.0.0.1]) - USER mk: Login successful.

Mar  7 20:07:25 www xinetd[29617]: START: telnet pid=30974 from=127.0.0.1

[root@www /root]# tail -f /var/log/secure        /* ½Ç½Ã°£À¸·Î º¸±â */

ÀÔÃâ·Â ÀçÁöÁ¤ (I/O redirection)

Å°º¸µå¿Í ¸ð´ÏÅÍ·Î ¼³Á¤µÇ¾î Àִ ǥÁØ ÀÔÃâ·ÂÀÇ ¹æÇâÀ» ÆÄÀÏÀ̳ª ´Ù¸¥ ÀåÄ¡·Î ÀçÁöÁ¤ÇÏ´Â °ÍÀ» ¸»ÇÑ´Ù.

¿¹) $ ls dir1 > ls.out          (ls dir1 ¸í·ÉÀÇ °á°ú¸¦ ls.out ¶ó´Â ÆÄÀÏ¿¡ Ãâ·ÂÇÑ´Ù)

    $ cat <file1 >file2          (file1À» cat ¸í·ÉÀÇ ÀÔ·ÂÀ¸·Î ¹Þ¾Æ ±× °á°ú¸¦ file2·Î Ãâ·ÂÇÑ´Ù)

    $ cat file1 >> file2        (file1ÀÇ ³»¿ëÀ» file2¿¡ µ¡ºÙÀδÙ)

    $ cat < file1 >> file2  (file1À» cat ¸í·ÉÀÇ ÀÔ·ÂÀ¸·Î ¹Þ¾Æ ±× °á°ú¸¦ file2¿¡ µ¡ºÙÀδÙ)

ex) cat lilo.conf > test_cat Àº cat < lilo.conf > test_cat°ú °°´Ù.


Ç¥ÁØ ÀÔÃâ·Â(Standard Input and Output)

shell ¸í·É¾î¿¡´Â 3°¡ÁöÀÇ Ç¥ÁØ ÀÔÃâ·ÂÀÌ ÀÖ´Ù.

stdin (0)  : Å°º¸µå¿¡¼­ µé¾î¿À´Â ÀÔ·ÂÀ» ¸»ÇÑ´Ù.

stdout (1) : »ç¿ëÀÚÀÇ Å͹̳Î(ÄܼÖ)·Î º¸³»Áö´Â Ãâ·ÂÀ» ¸»ÇÑ´Ù.

             Ãâ·ÂÀº ÇÁ¸°Åͳª ÆÄÀϷεµ °¥ ¼ö°¡ ÀÖ´Ù.

stderr (2) : Ç¥ÁØ ¿¡·¯·Î »ç¿ëÀÚÀÇ Å͹̳Î(ÄܼÖ)·Î º¸³»Áø´Ù.

ÆÄÀÌÇÁ (|)

ÀÔÃâ·Â ÀçÁöÁ¤ ±â´ÉÀ» È®ÀåÇؼ­ ÇÑ ÇÁ·Î±×·¥ÀÇ Ãâ·Â °á°ú¸¦ ´Ù¸¥ ÇÁ·Î±×·¥ÀÇ ÀÔ·ÂÀ¸·Î Á÷Á¢ ¿¬°á½ÃÅ°´Â ±â´ÉÀ» ¸»ÇÑ´Ù.

¿¹)

[root@www /root]# ls -l | more     /*  ls -l ¸í·ÉÀÇ °á°ú¸¦ ÆäÀÌÁö ´ÜÀ§·Î Ãâ·ÂÇÑ´Ù.  */

[root@www /root]# cat /etc/passwd |grep mk    

mk:x:500:500::/home/mk:/bin/bash

[root@www /root]# cut -f 1  -d ":"  /etc/passwd |sort |tail -5

shutdown

sook

sync

uucp

xfs

/*  /etc/passwd ÆÄÀÏÀÇ Ã¹ ¹ø° ÇÊµå °ªÀ» ÃßÃâÇÏ¿© ±× °á°ú¸¦ Á¤·ÄÇÏ¿© º¸¿©ÁØ´Ù. */

find

fileÀ̳ª directory¸¦ ã´Â´Ù. locate¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Ù.

[Çü½Ä]

[root@localhost/root]# find   .    -name   mk.txt  

                                °æ·Î   Ç¥Çö¹ý    file ¶Ç´Â directory¸í

°æ·Î´Â .(ÇöÀç µð·ºÅ丮)À¸·Î °Ë»öÇÒ ¼ö ÀÖÀ¸¸ç, /·Î Àüü µð·ºÅ丮¿¡¼­ °Ë»öÇÒ ¼öµµ ÀÖ´Ù.

file¸íÀ̳ª directory¸í¿¡´Â ¡®*¡¯³ª, ¡®?¡¯°°Àº wild-card¸¦ »ç¿ëÇÒ ¼ö Àִµ¥, ÀÌ·² ¶§´Â ¹Ýµå½Ã ¡®¡¯³ª ¡°¡±¸¦ »ç¿ëÇؼ­ ¹­¾î ÁÖ¾î¾ß ÇÑ´Ù.

UnixÀÇ °æ¿ì ¸ÇµÚ¿¡ -print ºÙ¿©¾ß È­¸é¿¡ Ãâ·ÂÀ» ÇÑ´Ù. ¸®´ª½º´Â µðÆúÆ®°¡ È­¸é Ãâ·ÂÀ¸·Î ÁöÁ¤µÇ¾î ÀÖ´Ù.

ÀÌ¿Ü¿¡µµ ¸¹Àº ¿É¼ÇÀÌ Á¸ÀçÇϹǷΠ¹Ýµå½Ã man ÆÄÀÏÀ» Âü°íÇϱ⠹ٶõ´Ù.

ºü¸¥ °Ë»öÀ» À§Çؼ­´Â locate¸¦ »ç¿ëÇϸç, ¸í·É¾î ¹× °æ·Î¸¦ °Ë»öÇÒ ¶§´Â which³ª whereis¸¦ ÀÌ¿ëÇÑ´Ù.

¿¹)

[root@lsrg log]# find / -name "stdi*.h"

/usr/include/bits/stdio-lock.h

/usr/include/bits/stdio.h

/usr/include/bits/stdio_lim.h

/usr/include/stdint.h

/usr/include/stdio.h

locate

findó·³ file ¶Ç´Â µð·ºÅ丮¸¦ ãÀ» ¶§ ¾²´Â ¸í·ÉÀε¥, find´Â Àüü¸¦ °Ë»öÀ» ÇÏ´Â ¹Ý¸é, locate´Â DB¸¦ ÀÌ¿ëÇÑ´Ù. ÀÌ ¶§ »ç¿ëµÇ´Â DB´Â /var/lib/slocate/slocatedbÀÌ´Ù.

locate´Â cron daemon¿¡ ÀÇÇØ ÇÏ·ç¿¡ Çѹø¾¿ °»½ÅµÈ´Ù.

DB ¾÷µ¥ÀÌÆ®

[root@lsrg log]# updatedb

¿¹)

[root@lsrg log]# locate stdio.h

/usr/include/bits/stdio.h

/usr/include/stdio.h

which / whereis

¸í·É¾î °Ë»ö½Ã¿¡´Â find ³ª locate º¸´Ù´Â which¿Í whereis¸¦ ¸¹ÀÌ »ç¿ëÇÑ´Ù. which´Â alias¸í°ú ¸í·É¾îÀÇ °æ·Î¸¦ ³ªÅ¸³»¸ç, whereis´Â ¸Å´º¾óÀÇ À§Ä¡¿Í ¸í·É¾îÀÇ °æ·Î¸¦ ³ªÅ¸³½´Ù.

[root@www /root]# which ls

alias ls='ls --color=tty'

        /bin/ls

[root@www /root]# whereis ls

ls: /bin/ls /usr/share/man/man1/ls.1.gz

df

partitionº°·Î Àüü ¿ë·®°ú ÇöÀç ³²Àº ¿ë·®À» È®ÀÎÇÒ ¼ö ÀÖÀ½. µû¶ó¼­ system °ü¸®¿¡ ²À ÇÊ¿äÇÏ´Ù.

À̶§, »ç¿ëµÈ ¿ë·®ÀÌ 100%°¡ µÇ¸é systemÀÌ down µÉ ¼öµµ ÀÖ´Ù.

KB ´ÜÀ§·Î È®ÀÎÇÏ°í ½ÍÀ» ¶§´Â -k ¿É¼ÇÀ» »ç¿ëÇϴµ¥, ±× º¸´Ù´Â ¿ë·®¿¡ µû¶ó ¾Ë¸Â°Ô K, M, GµîÀÇ ´ÜÀ§·Î Ãâ·ÂÇØ ÁÖ´Â -h ¿É¼ÇÀ» ´õ ¸¹ÀÌ »ç¿ëÇÑ´Ù.

[root@lsrg /root]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/hda5             2.9G   45M  2.6G   2% /

/dev/hda1              38M  2.8M   33M   8% /boot

/dev/hda9              11G  5.9G  5.0G  54% /home

/dev/hda6             2.9G  941M  1.8G  34% /usr

/dev/hda7             988M  111M  827M  12% /var

du

µð·ºÅ丮ÀÇ »ç¿ë·®À» Ãâ·ÂÇÑ´Ù.

Çհ踦 Ãâ·ÂÇϱâ À§ÇÑ ¿É¼Ç -s¿Í df¸í·É¿¡¼­¿Í °°Àº -h ¿É¼ÇÀ» ÇÔ²² »ç¿ëÇϸé Á» ´õ Àб⠽¬¿î °á°ú¸¦ ¾òÀ» ¼ö ÀÖ´Ù.

[root@lsrg /root]# du -h

8.0k    ./.ssh

92k     .

Á¤±ÔÇ¥Çö½Ä

*  : ¿©·¯°³ÀÇ ¹®ÀÚ¸¦ ´ëÇ¥ÇÑ´Ù.    

[root@localhost /etc]#ls -l host*


?  : ÇÑ°³ÀÇ ¹®ÀÚ¸¦ ´ëÇ¥ÇÑ´Ù.      

[root@localhost /root]#ls -l host*.????

[123] 1 or 2 or 3, [1-5] 1ºÎÅÍ 5 :  ¾î¶°ÇÑ ¹üÀ§¸¦ Ç¥Çö

[root@localhost /etc]#ls -l [a-b]*

^pattern : ÇØ´ç ±ÛÀÚ·Î ½ÃÀÛÇÏ´Â ¶óÀÎ °Ë»ö

[root@www /root]# grep ^image /etc/lilo.conf

image=/boot/vmlinuz-2.4.2-2Áö

pattern$ : ÇØ´ç ±ÛÀÚ·Î ³¡³ª´Â ¶óÀÎ °Ë»ö

[root@www /root]# grep linux$ /etc/lilo.conf

default=linux

        label=linux

  Hit : 10426     Date : 2004/07/04 02:47



    
1541   [[ÃʱÞ/°­ÁÂ]] À¯´Ð½º ÁÖ¿ä ¸í·É¾î[7]     ¼ÒÀ¯
10/09 14595
1540   [[ÃʱÞ/°­ÁÂ]] À¯´Ð½º ±âº» Á¤¸®[8]     ¼ÒÀ¯
10/09 14483
1539     [re] ÇãÁ¢ÆÁ] ¾ÏÈ£¸¦ ¹Ù²ã ÇØÅ·ÇÇÇØ ÁÙÀÌÀ𠤻 ^^; ´õ ÁÁÀº¹æ¹ý[9]     xeon400
10/14 9396
1538   Äְܼú ¿¢½ºÀ©µµ¿¡¼­ ¸¶¿ì½º »ç¿ëÇϱâ[1]     ¼ÒÀ¯
10/28 10033
1537   ¸®´ª½º¿¡¼­ Çѱ¹Åë½Å adsl ¼³Á¤[10]     jgminam
11/06 11542
1536   gdb»ç¿ë¹ý_¸µÅ©ÀÓ´Ù...[3]     esang72
01/10 8895
1535   ¸®¸ðÆ®¿¡¼­ ¸í·É¾î ½ÇÇà½ÃÅ°±â[1]     xiangyi
02/03 10639
1534   format stringÀ» À§ÇÑ ¸®ÅϾîµå·¹½º ±¸Çϱâ.[2]     ssuckies
02/08 10716
1533   ±×³àÀÇ Vulnerabilities¿¡ µû¸¥ Remote/local one night stand exploit.[2]     ssuckies
03/29 10204
1532   ¿Ö C À̾î¾ß Çϴ°¡ ?[96]     ¼ÒÀ¯
04/09 25099
1531   BOF ÇØ°á ¹«ÀÛÁ¤ µû¶óÇϱâ #1[7]     ssuckies
04/12 14520
1530   BOF ÇØ°á ¹«ÀÛÁ¤ µû¶óÇϱâ #2     ssuckies
04/12 10081
1529   Ä¿³Î¹öÀü È®ÀÎÇϱ⤻[1]     ±«µµjs
07/02 9139
1528   [C°­ÁÂ] C¾ð¾îÀÇ ±âº»°³¿ä     ±«µµjs
07/02 11296
1527   C¾ð¾î ±âº»±¸Á¶[1]     ±«µµjs
07/02 12537
1526   C°­ÁÂ;;¶ó ÇÒ°ÍÀÕ³ª?[1]     ±«µµjs
07/03 11280
1525   2¹ø°C°­ÁÂ~![9]     ±«µµjs
07/03 11980
1524   I. ¸®´ª½º ±¸Á¶ ¹× ÀÏ¹Ý ¸í·É¾î.     ±«µµjs
07/04 12857
  II. ÀϹݸí·É¾î2.     ±«µµjs
07/04 10425
1522   [Bash Shell] Á¤º¹Çϱâ[1]     ±«µµjs
07/04 10124
[1][2] 3 [4][5][6][7][8][9][10]..[80]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org