我怎麼能在 bash shell 中進行這樣的搜尋?
1)搜尋名稱開頭為的所有文件mysql-(然後是其他內容)到特定資料夾(及其所有子資料夾)
2)搜尋特定資料夾中的某些檔案(設定\文字)中是否存在以以下內容開頭的內容mysql-(然後是其他的東西)
答案1
你的問題有點混亂,但據我了解:
1)您想要尋找mysql-
特定資料夾(目錄)及其子樹中以以下開頭的所有檔案:
find <your directory here> -name "mysql-*"
2)尋找指定目錄中包含以下內容的所有檔案mysql-
:
cd <your directory here> && grep -R mysql- *
如果你真的只想要檔案名,請加入剪切過濾器:
cd <your directory here> && grep -R mysql- * | cut -d ":" -f1 | sort | uniq
答案2
使用
find
命令:find MYDIR -iname mysql-* -type f
使用
grep
命令:grep -rn 'mysql-' MYDIR