grep

English ['grep] US ['grep]

[??] ?? ?? ?? ??

??? grep ?? ???

??: grep ??? ???? ??? ???? ???? ?? ? ?????.

??: ??grep [-abcEFGhHilLnqrsvVwxy][-A<? ?? ??>][-B<? ?? ??>][-C<?? ??>][-d<?? ??>] [-e< ??? ???>][-f][--help][??? ???][?? ?? ????...]

??? grep ?? ?

1. ?? ?????? file??? ??? ?? ???? ??? ???? ??? ??? ?? ?? ???? ?? ?????. ?? ?? ???? ??? ? ????.

grep test *file

??? ??? ????.

$ grep test test* #查找前綴有“test”的文件包含“test”字符串的文件  
testfile1:This a Linux testfile! #列出testfile1 文件中包含test字符的行  
testfile_2:This is a linux testfile! #列出testfile_2 文件中包含test字符的行  
testfile_2:Linux test #列出testfile_2 文件中包含test字符的行

2. ??? ?? ??? ????? ????. ?? ??, ??? /etc/acpi ????? ? ?? ????(?? ????? ???? ??)? ?? ???? "update"?? ???? ??? ??? ?? ?? ???? ?? ?? ??? ????? ?? ??? ?????. :

grep -r update /etc/acpi

?? ??? ??? ????.

$ grep -r update /etc/acpi #以遞歸的方式查找“etc/acpi”  #下包含“update”的文件  
/etc/acpi/ac.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of IO.)  Rather than  
/etc/acpi/resume.d/85-anacron.sh:# (Things like the slocate updatedb cause a lot of  
IO.) Rather than  
/etc/acpi/events/thinkpad-cmos:action=/usr/sbin/thinkpad-keys--update

3. ?? ??? ??? ?? ??? ?? ???? ??????. "-v" ????? ???? ??? ?? ?? ??? ??? ??? ? ????.

?? ??? test? ??? ???? test? ???? ?? ?? ????. ?? ??? ???

grep -v test *test*

??? ??? ????.

$ grep-v test* #查找文件名中包含test 的文件中不包含test 的行  
testfile1:helLinux!  
testfile1:Linis a free Unix-type operating system.  
testfile1:Lin  
testfile_1:HELLO LINUX!  
testfile_1:LINUX IS A FREE UNIX-TYPE OPTERATING SYSTEM.  
testfile_1:THIS IS A LINUX TESTFILE!  
testfile_2:HELLO LINUX!  
testfile_2:Linux is a free unix-type opterating system.