如何在 Git Bash 中使用 Find、Grep 和 Exec 複製 grep 文件

如何在 Git Bash 中使用 Find、Grep 和 Exec 複製 grep 文件

我到處尋找答案,但似乎沒有任何結果。在 Git Bash 中,我需要弄清楚如何取得使用 grep 找到的檔案並將它們複製到其他地方。說明是使用 find、grep 和 exec 指令來執行此操作。我已經使用 grep 命令找到了需要複製的檔案(即 grep -rli [搜尋字詞] *),那麼如何將其放入 find exec 命令中進行複製?

答案1

你可以使用:

find . -name "*.exe" -exec cp {} ~/Documents \;

不知道為什麼你需要使用 exec,但否則你可以使用例如:

find . -name "*.exe" | grep something | xargs cp -t ~/Documents
find . -name "*.exe" | grep something | xargs -I {} cp {} ~/Documents # more intuitive with placeholders

相關內容