Đây là một câu trả lời hoàn chỉnh xuất phát từ câu trả lời của Ketan và daniel kullman, cũng như nghiên cứu của riêng tôi.
Hầu hết các "tính năng" hóa ra là tối ưu hóa truy vấn, vì findnói chung có khả năng (gần như) các truy vấn phức tạp tùy ý trên hệ thống tệp.
D_TYPE
Sự hiện diện của D_TYPEtính năng có nghĩa là findđã được biên dịch với sự hỗ trợ cho d_typetrường trong struct dirent. Trường này là một phần mở rộng BSD cũng được Linux chấp nhận, nó cung cấp loại tệp (thư mục, tệp, đường ống, ổ cắm, thiết bị char / block, v.v.) trong cấu trúc được trả về từ readdirvà bạn bè. Để tối ưu hóa, findcó thể sử dụng điều này để giảm hoặc loại bỏ lstatcác cuộc gọi khi -typeđược sử dụng làm biểu thức lọc.
readdircó thể không phải lúc nào cũng cư trú d_typetrên một số hệ thống tập tin, vì vậy đôi khi lstatvẫn sẽ cần thiết.
Thông tin thêm từ tài liệu chính thức: https://www.gnu.org/software/findutils/manual/html_node/find_html/d_005ftype-Optimisation.html
O_NOFOLLOW
Tùy chọn này sẽ đọc (enabled)hoặc (disabled). Nếu có và được kích hoạt, tính năng này thực hiện một biện pháp bảo mật bảo vệ findkhỏi các cuộc tấn công chủng tộc TOCTTOU nhất định. Cụ thể, nó ngăn chặn truyền tải findmột liên kết tượng trưng trong khi thực hiện truyền tải thư mục, điều này có thể xảy ra nếu thư mục được thay thế bằng một liên kết tượng trưng sau khi tệp kiểu của thư mục được kiểm tra nhưng trước khi thư mục được nhập.
Với tùy chọn này được bật, findsẽ sử dụng open(..., O_NOFOLLOW)trên thư mục để chỉ mở các thư mục thực, sau đó sử dụng openatđể mở các tệp trong thư mục đó.
LEAF_OPTIMISATION
Tối ưu hóa hơi khó hiểu này cho phép findsuy ra thư mục con nào của thư mục mẹ là thư mục bằng cách sử dụng số lượng liên kết của thư mục mẹ, vì thư mục con sẽ đóng góp vào số lượng liên kết của cha mẹ (thông qua ..liên kết). Trong một số trường hợp nhất định, nó sẽ cho phép findbỏ qua một statcuộc gọi. Tuy nhiên, nếu hệ thống tập tin hoặc hệ điều hành sai st_nlinks, nó có thể gây findra kết quả không có thật (điều này rất may là rất hiếm khi xảy ra).
Thông tin thêm trong tài liệu chính thức: https://www.gnu.org/software/findutils/manual/html_node/find_html/Leaf-Optimisation.html
FTS
Khi được bật, FTStính năng này sẽ findsử dụng ftsAPI để duyệt qua cấu trúc phân cấp tệp, thay vì triển khai đệ quy thẳng.
Tôi không rõ lợi thế của ftsnó là gì, nhưng FTSvề cơ bản là mặc định trên tất cả các findphiên bản mặc định mà tôi đã thấy cho đến nay.
Thông tin thêm: https://www.gnu.org/software/findutils/manual/html_node/find_html/raft.html , http://man7.org/linux/man-pages/man3/raft.3.html
CBO
Hóa ra (sau khi đọc findmã nguồn theo đề xuất của daniel kullman) rằng "CBO" đề cập đến mức tối ưu hóa truy vấn (viết tắt của "trình tối ưu hóa dựa trên chi phí"). Ví dụ, nếu tôi làm find -O9001 --version, tôi nhận được
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=9001)
Nhìn vào -Otùy chọn trong man find, tôi thấy
-Olevel
Enables query optimisation. The find program reorders tests to speed up execution while preserving the overall
effect; that is, predicates with side effects are not reordered relative to each other. The optimisations performed
at each optimisation level are as follows.
0 Equivalent to optimisation level 1.
1 This is the default optimisation level and corresponds to the traditional behaviour. Expressions are
reordered so that tests based only on the names of files (for example -name and -regex) are performed first.
2 Any -type or -xtype tests are performed after any tests based only on the names of files, but before any
tests that require information from the inode. On many modern versions of Unix, file types are returned by
readdir() and so these predicates are faster to evaluate than predicates which need to stat the file first.
3 At this optimisation level, the full cost-based query optimiser is enabled. The order of tests is modified
so that cheap (i.e. fast) tests are performed first and more expensive ones are performed later, if neces-
sary. Within each cost band, predicates are evaluated earlier or later according to whether they are likely
to succeed or not. For -o, predicates which are likely to succeed are evaluated earlier, and for -a, predi-
cates which are likely to fail are evaluated earlier.
The cost-based optimiser has a fixed idea of how likely any given test is to succeed. In some cases the probability
takes account of the specific nature of the test (for example, -type f is assumed to be more likely to succeed than
-type c). The cost-based optimiser is currently being evaluated. If it does not actually improve the performance
of find, it will be removed again. Conversely, optimisations that prove to be reliable, robust and effective may be
enabled at lower optimisation levels over time. However, the default behaviour (i.e. optimisation level 1) will not
be changed in the 4.3.x release series. The findutils test suite runs all the tests on find at each optimisation
level and ensures that the result is the same.
Giải đáp bí ẩn! Có một điều lạ là tùy chọn này là một giá trị thời gian chạy; thông thường tôi chỉ mong đợi --versionđầu ra chỉ phản ánh các tùy chọn thời gian biên dịch.