如何找出一個目錄下包含某個字符串的所有文件?linux提供的grep命令可以很快做到:
命令格式:
grep 要搜索的字符串 目錄路徑(相對或絕對路徑都可以)
如
grep block app/design/frontend/default/coow/layout/*
這是輸出的一部分:
app/design/frontend/default/coow/layout/tag.xml: </block>
app/design/frontend/default/coow/layout/tag.xml: <block
type="tag/customer_tags" name="customer_tags"
template="tag/customer/tags.phtml"/>
app/design/frontend/default/coow/layout/tag.xml: <block
type="tag/customer_view" name="customer_view"
template="tag/customer/view.phtml"/>
app/design/frontend/default/coow/layout/tag.xml: <block
type="tag/customer_edit" name="customer_edit"
template="tag/customer/edit.phtml"/>
上面命令只能搜索該目錄下當前目錄的文件,而不能搜索子目錄中的文件夾。加上-R 選項可以讓grep遞歸的搜索整個目錄。加上-n選項可以讓grep指示出在文件中的哪一行找到的字符串:
grep -Rn block app/design/frontend/default/coow/layout/*
app/design/frontend/default/coow/layout/tag.xml:85:
<block type="tag/all" name="tags_all" template="tag/cloud.phtml"/>
app/design/frontend/default/coow/layout/tag.xml:92:
<block type="tag/product_result" name="tag_products"
template="catalogsearch/result.phtml">
app/design/frontend/default/coow/layout/tag.xml:93:
<block type="catalog/product_list" name="search_result_list" template