Syntax
Description
Thefind command recursively searches for files and directories within Nash’s virtual filesystem. It supports filtering by name patterns (with glob wildcards), file type, and maximum search depth. Each matching path is printed on a separate line.
Find operates within Nash’s Virtual Filesystem (VFS). When searching mounted host directories, it searches through the VFS mount point.
Options
Filter results by filename pattern using glob syntax. Supports wildcards:
*matches zero or more characters?matches exactly one character
-name "*.txt" finds all files ending in .txtFilter results by entry type:
f- regular files onlyd- directories only
Limit the depth of directory traversal. For example,
-maxdepth 1 searches only the specified directory without descending into subdirectories.Note: Depth counting starts at 0 for the initial directory.Arguments
Starting directory for the search. Can be absolute or relative to the current working directory. If omitted, searches from the current directory (
.).Behavior
- Starts from the specified path (or current directory)
- Recursively descends into subdirectories (unless limited by
-maxdepth) - Tests each entry against all specified filters (
-name,-type) - Outputs absolute paths of matching entries, one per line
- Includes the starting directory if it matches all filters
- Searches depth-first through the directory tree
Examples
Find all files in current directory
Find files by name pattern
Find only directories
Find only files
Search specific directory
Limit search depth
Combine multiple filters
Find with wildcards
Search from absolute path
Pattern Matching
The-name option supports glob patterns:
Asterisk (*) - Match any characters
Question mark (?) - Match single character
Combined patterns
Pattern matching is applied to the basename (filename) only, not the full path.
Use Cases
Locate configuration files
Find all source files
Count files by type
List only immediate subdirectories
Find empty directories
Search and process files
VFS Integration
Search mounted directories
Find searches through mounted host directories:Multiple mount points
Read-only mounts
Find works identically on read-only mounts:Error Handling
Non-existent directory
Find silently returns no results for non-existent paths:Permission errors in mounted directories
If a mounted directory has host-level permission issues, those paths are silently skipped.Combining with Other Commands
With rm to delete matched files
With grep to search file contents
With wc to count results
With tree to compare
With sort and uniq
Output Format
Find outputs absolute paths, one per line:/ in the output.
Exit Codes
- 0 - Success: search completed (even if no matches found)
Related Commands
tree- Display directory tree structure visuallyls- List directory contents non-recursivelygrep- Search file contents (combine with find for full-text search)pwd- Show current directory (default find starting point)cd- Change directory before searching
Implementation Details
Thefind command is implemented in /home/daytona/workspace/source/src/builtins/find.rs:9-125. Key implementation notes:
- Parses arguments to extract path,
-name,-type, and-maxdepthoptions - Uses
find_recursive()helper for depth-first traversal - Implements glob matching with
glob_match()function supporting*and?wildcards - Pattern matching is applied to basename only via
VfsPath::basename() - Depth counter starts at 0 for the initial path
-maxdepthapplies to recursion depth, not output filtering- All paths in output are absolute, resolved via
VfsPath::join() - Uses
vfs.is_dir()andvfs.list_dir()for filesystem traversal
Performance Considerations
Best practices for performance
Comparison to Traditional Unix find
Nash’sfind implements essential functionality:
| Feature | Nash find | Unix find |
|---|---|---|
-name pattern | ✓ Glob (* and ?) | ✓ Glob (* and ?) |
-type f|d | ✓ Supported | ✓ Supported (+more) |
-maxdepth N | ✓ Supported | ✓ Supported |
-iname | ✗ Not supported | ✓ Case-insensitive |
-size | ✗ Not supported | ✓ Filter by size |
-mtime | ✗ Not supported | ✓ Filter by time |
-exec | ✗ Not supported | ✓ Execute commands |
-regex | ✗ Not supported | ✓ Regex patterns |
-prune | ✗ Not supported | ✓ Skip directories |
| Logical ops | ✗ Not supported | ✓ -and, -or, -not |
For advanced filtering not supported by Nash’s find, pipe results to other commands like
grep, sed, or awk.