Design a Unix File Search System

Medium
File SystemsCompositeChain of ResponsibilityBuilder

Problem Statement

Design a Unix-like find command system that can search for files based on multiple criteria:

  • Search by name (exact or pattern with wildcards)
  • Search by size (greater than, less than, equal to)
  • Search by extension
  • Search by date modified
  • Combine criteria with AND/OR logic

Design Requirements

Key Entities:

  • File / Directory — Composite pattern (both are "FileSystemNode")
  • Filter — Interface for search criteria
  • NameFilter, SizeFilter, ExtensionFilter, DateFilter
  • AndFilter, OrFilter — Combine multiple filters
  • FileSearcher — Traverses the tree applying filters

Example Usage:

Filter f = new AndFilter(
    new ExtensionFilter("java"),
    new SizeFilter(1024, SizeFilter.GREATER_THAN)
);
List<File> results = searcher.search(rootDir, f);

!Constraints

- Directory tree can be deeply nested (up to 20 levels) - Support wildcard matching: * (any chars) and ? (single char) - Search must be recursive by default, with option to limit depth - Results should be returned sorted by path - Handle symlinks by not following them (avoid infinite loops)
Output

Run your code to see output here.