Skip to the content.

find 命令

基本操作

\; 和 +

https://stackoverflow.com/questions/29360925/whats-the-difference-between-and-at-the-end-of-a-find-command

\; 方式(逐个文件执行)

🧀  find . -name "*hotplug*" -type f -exec ls {} \;
./docs/kernel/hp/hotplug-nvme.md
./docs/kernel/hp/mm-hotplug.md
./docs/kernel/hp/sched-hotplug.sh
./docs/kernel/hp/hotplug.md
./docs/kernel/hp/sched-cpu-hotplug.md
./docs/kernel/hp/storage-hotplug.md
vn on  master [$+] 🔥
🤒   find . -name "*mmmm*" -type f -exec ls {} mmmm +
find: missing argument to `-exec'

但是 \; 就没有这个限制了

find 和 xargs 配合必须添加使用 print0

同时 xargs 必须 -0

参考 https://www.shellcheck.net/wiki/SC2038

By default, xargs interprets spaces and quotes in an unsafe and unexpected way. Whenever it’s used, it should be used with -0 or –null to split on \0 bytes, and find should be made to output \0 separated filenames.

-delete 参数

find . -size 0 -print0 -delete # 删除大小为 0 的文件”

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。