¹®Àڿã±â ¹æ¹ý 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