¿ù°£ Àα⠰Խù°

°Ô½Ã¹° 56°Ç
   
´Ù¾çÇÑ ¹®ÀÚ¿­ °Ë»ö
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2011-06-22 (¼ö) 22:06 Á¶È¸ : 7235
±ÛÁÖ¼Ò :
                          

 
¹®ÀÚ¿­Ã£±â ¹æ¹ý 1 - ¿µ¾î¸¸ ÁÖ·Î °¡´É
# grep -rw "ã´Â¹®ÀÚ¿­" ./

¹®ÀÚ¿­Ã£±â ¹æ¹ý 2 - ´ë/¼Ò¹®ÀÚ ±¸ºÐ ¾ÈÇÏ°í °Ë»ö
# grep -i -l "ã´Â¹®ÀÚ¿­" * -r 2> /dev/null

¹®ÀÚ¿­Ã£±â ¹æ¹ý 3 - ÇѱÛ, ¿µ¾î ¸ðµÎ °¡´É
# find . -exec grep -l "ã´Â¹®ÀÚ¿­" {} \\; 2>/dev/null

¹®ÀÚ¿­Ã£±â ¹æ¹ý 4 - ÇѱÛ,¿µ¾î, ´ë¼Ò¹®ÀÚ ¾È°¡¸®°í °Ë»ö
# find . -exec grep -i -l "ãÀ»¹®ÀÚ¿­" {} \\; 2>/dev/null

¹®ÀÚ¿­Ã£Àº ÈÄ Ä¡È¯
# find . -exec perl -pi -e 's/ãÀ»¹®ÀÚ¿­/¹Ù²Ü¹®ÀÚ¿­/g' {} \\; 2>/dev/null

ÆÄÀϸí ã±â
# find / -name ÆÄÀϸí -type f

ÆÄÀϸí ã±â(´ë¼Ò¹®ÀÚ ±¸º°¾øÀ½)
# find / -iname ÆÄÀϸí -type f

µð·ºÅ丮 ã±â
# find / -name ÆÄÀϸí -type d

µð·ºÅ丮 ã±â(´ë¼Ò¹®ÀÚ ±¸º°¾øÀ½)
# find / -iname ÆÄÀϸí -type d




ÇÏÀ§ µð·ºÅ丮¿¡ ¸ðµÎ Æ÷ÇÔÇÏ¿© ¹®ÀÚ¿­ ã±â
grep -rl [¹®ÀÚ¿­] *

r ¿É¼ÇÀÌ ¾ø´Ù¸é
find . * -exec grep -n [¹®ÀÚ¿­] {}\\; -print

´õ ª°íµµ È¿°úÀûÀÎ ¹æ¹ý
grep "string"'find . -type '


±×·±µ¥ ÀÌ´Â Á¶°Ç¿¡ ¸Â´Â ÆÄÀÏÀÇ °³¼ö°¡ ¸¹¾ÆÁö¸é ½©ÀÇ ¸í·ÉÇà ¹öÆÛÀÇ ¹üÀ§¸¦ ¹þ¾î³ª¹Ç·Î ¹®Á¦°¡µÉ ¼ÒÁö°¡ ÀÖ´Ù. ¸í·ÉÇà ¹öÆÛÀÇ ¿À¹öÇ÷ο츦 ¹æÁöÇϱâ À§Çؼ± ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù.

find . -type f | xargs grep "string"


±×·±µ¥ ÀÌ ¹æ¹ýÀº ÆÄÀÏ À̸§¿¡ °ø¹éÀÌ µé¾î°¥ °æ¿ì ¹®Á¦°¡ »ý±æ ¼ö ÀÖ´Ù. ±×·³ ´ÙÀ½°ú °°ÀÌ Çغ¸ÀÚ.
find . -type f -print0 | xargs -0 grep "string"


find´Â ½Éº¼¸¯ ¸µÅ©µÈ µð·ºÅ丮¿¡ ´ëÇؼ­´Â ±âº»ÀûÀ¸·Î °Ë»öÀ» ½Ç½ÃÇÏÁö ¾ÊÀ¸´Ï -follow¿É¼ÇÀ» »ç¿ëÇؾßÇÒ °æ¿ìµµ ÀÖ´Ù´Â °ÍÀ» ¾Ë¾ÆµÐ´Ù.

¸í·ÉÇà ¹öÆÛ¿À¹öÇ÷ο츦 ¹æÁöÇÏ´Â ¹æ¹ýÀº ´ÙÀ½°ú °°Àº ¹æ¹ýµµ ÀÖ´Ù.

find . -type f -exec grep -l"string" {}¡¬;


grep¿¡¼­ '-l'¿É¼ÇÀº stringÀ» Æ÷ÇÔÇÏ´Â ÆÄÀϸíÀ» ³ªÅ¸³»ÁØ´Ù. ÀÌ·± °Ë»öÀ» ƯÁ¤ ÆÄÀϵ鿡 ´ëÇؼ­ ÇàÇϱâ À§Çؼ­´Â -type¿Í -name¿É¼ÇÀ» ¾µ ¼ö ÀÖ´Ù.
find . ¡¬(-type f -name "*¡¬.html"¡¬) -exec grep -l "string" {}¡¬;


ÀÌ°ÍÀº htmlÀÇ È®ÀåÀÚ¸¦ °¡Áö´Â ¸ðµç ÆÄÀÏ¿¡ ´ëÇؼ­ "string"À» Æ÷ÇÔÇÏ´ÂÁö ¾Ë¾Æº¸°í Æ÷ÇÔÇÏ°í ÀÖ´Â ÆÄÀϸíÀ» Ãâ·ÂÇØÁØ´Ù.

À§ÀÇ ¹æ¹ýµéÀº "¾î¶»°Ô ¼­ºêµð·ºÅ丮¿¡ ÀÖ´Â ÆÄÀϵ鿡 ´ëÇؼ­ grepÀ» ½ÇÇàÇØÁÙ ¼ö Àִ°¡?"ÇÏ´Â ¹®Á¦¿¡ °üÇÑ ¿©·¯ °¡Áö ¹æ¹ýµéÀº ¸Å¿ì À¯¿ëÇϱä ÇÏÁö¸¸ °Ë»öÀ» ½Ç½ÃÇÏ´Â µð·ºÅ丮¿¡ ¹ÙÀ̳ʸ® ÆÄÀÏÀÌ ÀÖÀ» °æ¿ì¿¡´Â Å͹̳ÎÀ» Á¦¾îÇÏÁö ¸øÇÏ´Â ¹®Á¦°¡ »ý±æ ¼ö ÀÖ´Ù. ¿Ö³ÄÇÏ¸é ¹ÙÀ̳ʸ® ÆÄÀÏÀÇ ¸î¸î Á¦¾î ¹®ÀÚµé(Control Characters)ÀÌ Å͹̳ÎÀ» ±×·¡ÇÈ ¸ðµå·Î ¹Ù²ã³õÀ» ¼ö Àֱ⠶§¹®ÀÌ´Ù. ¹°·Ð ÀÌ·¸°Ô µÇ¾úÀ» °æ¿ì Å͹̳ÎÀ» ´Ù½Ã ¹Ù·ÎÀâ´Â ¹æ¹ýÀÌ ÀÖ±ä ÇÏÁö¸¸ ¾Æ¹«·¡µµ °¡Àå ÁÁÀº ¹æ¹ýÀº ±×·¯ÇÑ ÀÏÀÌ ¾øµµ·Ï óÀ½ºÎÅÍ ¹æÁöÇÏ´Â °ÍÀÌ °¡Àå ÁÁÀ» °ÍÀÌ´Ù.
ÀÌÁ¦ È­¸é¿¡ ÂïÇô³ª¿Ã ¼ö ¾ø´Â ¹®ÀÚµéÀ» ¸ðµÎ ¾ø¾Öº¸ÀÚ. ¾î·µç ÀÐÀ» ¼ö´Â ¾øÁö¸¸ ´ÙÀ½°ú °°Àº ¸í·ÉÀ» ³»·Áº¸¶ó.

sed -e 's/[^-~][^-~]*//g'

ÀÌ ¸í·ÉÀº È­¸é¿¡ Ãâ·ÂµÉ ¼ö ¾ø´Â (Á¦¾î) ¹®ÀÚµéÀ» ±×³É ½ºÆäÀ̽ºµé·Î ¹Ù²ã ¹ö¸°´Ù. ÀÌ ¸í·ÉÀº ÆÄÀÌÇÁ¸¦ ÀÌ¿ëÇÏ¿© ½±°Ô ´Ù¸¥ ¸í·É¾îµé°ú °áÇÕÇؼ­ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¿©±â °£´ÜÇÑ ½© ½ºÅ©¸³Æ®°¡ ÀÖ´Ù. ÀÌ°ÍÀ» grepfind¶ó°í À̸§ºÙ¿©¼­ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

#!/bin/sh
#save this in a file called grepfind and do a "chmod 755 grepfind"
#
if test $@ = 0 -o "$1" = "-h" -o "$1" = "-help" ; then
echo 'grepfind ¦¡ recursively descends directories and egrep all files '
echo
echo 'Usage: grepfind [-help][-h](start_directory] egrep_search_pattern'
echo
echo 'The surrent directory is used as start_directory if parameter'
echo 'start_directory is omitted. The search is case insensitive.'
echo 'Multiple occurrences of control characters are replaced by a single'
echo 'space. This makes it possible to grep around in files that contain'
echo 'binary data and strings without setting the terminal accidently'
echo 'to graphics mode.'
echo
echo 'Example : grepfind/home "hello world"
else
if ["$2" = "" ];then
find . -type f -exec egrep -i "$1" /dev/null {} ¡¬;|sed -e 's/[^-~][^-~]*//g'
else
if [-d "$1" ] ;then
find $1 -type f -exec egrep -i "$2" /dev/null {} ¡¬;|sed -e 's/[^-~][^-~]*//g'
else
echo "ERROR: $1 is not a directory"
fi
fi
fi
#_END_OF_grepfind

À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.