Có một vài lý do tiềm năng cho việc này.
1)
Bạn bảo nó chỉ xóa các thư mục ( -type d) và các thư mục đó vẫn có các tệp bên trong chúng.
2) Thư mục
của bạn chỉ chứa các thư mục khác, vì vậy -type dsẽ giải quyết vấn đề nội dung. Tuy nhiên, bạn đang sử dụng OS-X, phần lớn dựa trên FreeBSD và FreeBSD findtheo mặc định sẽ xử lý thư mục trước nội dung của nó.
Tuy nhiên, -depthtùy chọn tồn tại để giải quyết vấn đề này bằng cách yêu findcầu xử lý thư mục sau nội dung của nó.
find ~ -name __pycache__ -type d -ls -delete -depth
Vấn đề này không tồn tại trên linux vì -deletetùy chọn này hoàn toàn cho phép -depth.
FreeBSD man 1 find:
-depth Always true; same as the non-portable -d option. Cause find to
perform a depth-first traversal, i.e., directories are visited in
post-order and all entries in a directory will be acted on before
the directory itself. By default, find visits directories in
pre-order, i.e., before their contents. Note, the default is not
a breadth-first traversal.
GNU man 1 find:
-depth Process each directory's contents before the directory itself. The -delete
action also implies -depth.
find ~ -path '*/__pycache__*' -deletehoặc có thểfind ~ -path '*/__pycache__/*' -o -name __pycache__ -deletelà an toàn.