如何找到一堆文件名(或正文)中带有字符串的文件,然后将所有这些文件移动到特定文件夹?

Inq*_*Kea 5 find search filenames rename

说 - 如果我想将文件名中带有“heavengames”一词的几个独立目录中的每个 HTML 文件(以及作为第二个问题,其正文中带有“heavengames”一词的每个 HTML 文件)移动到一个名为“天堂游戏线程”?

rus*_*ush 4

要移动名称中包含该单词的文件:

find /path/to/dir1 /path/to/dir2 /and/so/on -type f -iname "*heavengames*" \
-exec mv -t /path/to/heavengames-threads {} \+
Run Code Online (Sandbox Code Playgroud)

要移动正文中包含 word 的文件:

find /path/to/dir1 /path/to/dir2 /and/so/on -type f -exec grep -q heavengames {} \; \
-exec mv -t /path/to/heavengames-threads {} \+
Run Code Online (Sandbox Code Playgroud)

附:要检查一切是否正确,请在第一次运行时添加echobefore 。mv