Find
如何將 find 命令(使用 grep)的輸出重定向到日誌文件?
考慮搜尋包含模式“搜尋字元串”的所有文件的程式碼:
bash-3.2$ # The below find works fine.. bash-3.2$ find . -type f -exec grep -il "search string" {} \; bash-3.2$ # But I am unable to redirect output to a log file.. bash-3.2$ find . -type f -exec grep -il "search string" {} \ > log.txt find: incomplete statement bash-3.2$
從 Solaris 的手冊頁中找到:
-exec command True if the executed command returns a zero value as exit status. The end of command must be punctuated by an escaped semicolon. A command argument {} is replaced by the current path name.
因此,似乎必須使用轉義的分號。還有其他方法可以解決這個問題嗎?
您正在刪除
\;
. 只需這樣做:find . -type f -exec grep -il "search string" {} \; > log.txt