Skip to content

Search

VFS provides powerful search capabilities for finding files by name, content, and attributes.

VFS uses SQLite FTS5 for fast full-text search across all file contents.

avfs search <query>

Examples:

$ avfs search "database connection"
/src/db.rs:15: let connection = Database::connect(url)?;
/docs/setup.md:42: Configure your database connection string...
/config/example.yaml:8: database_connection: postgres://...

$ avfs search "TODO"
/src/main.rs:23: // TODO: implement error handling
/src/lib.rs:89: // TODO: add tests

Search in Directory

avfs search "query" /path/

Search Options

Option Description
--limit <N> Limit results
--rebuild Rebuild search index
--json JSON output

FTS5 Query Syntax

VFS supports SQLite FTS5 query syntax for advanced searches:

# Phrase search
avfs search '"exact phrase"'

# AND (default)
avfs search "database connection"  # finds both words

# OR
avfs search "error OR warning"

# NOT
avfs search "config NOT test"

# Prefix matching
avfs search "data*"  # matches database, datatype, etc.

The grep command provides regex-based searching with more control.

Basic Grep

avfs grep <pattern> [path]

Examples:

$ avfs grep "fn \w+\(" /src/
/src/main.rs:5:fn main() {
/src/main.rs:12:fn process_args(args: &[String]) -> Result<Config> {
/src/lib.rs:8:fn new() -> Self {

Regex Patterns

VFS uses Rust's regex crate:

# Character classes
avfs grep "[0-9]+" /data/          # Numbers
avfs grep "[A-Z][a-z]+" /docs/     # Capitalized words

# Quantifiers
avfs grep "colou?r" /docs/         # color or colour

# Anchors
avfs grep "^import" /src/          # Lines starting with import
avfs grep ";\s*$" /src/            # Lines ending with semicolon

# Groups
avfs grep "(TODO|FIXME|HACK)" /src/

Grep Options

Option Description
-i, --ignore-case Case-insensitive
-n, --line-numbers Show line numbers (default)
-l, --files-with-matches Only show filenames
-c, --count Show match count
--limit <N> Limit results

Context Lines

# 3 lines after each match
$ avfs grep -A 3 "fn main" /src/main.rs
/src/main.rs:5:fn main() {
/src/main.rs-6-    let args: Vec<String> = env::args().collect();
/src/main.rs-7-    let config = process_args(&args)?;

# 2 lines before and after
avfs grep -C 2 "error" /logs/app.log

Find - Locate Files

The find command locates files by name, attributes, and metadata.

Find by Name

avfs find [path] -n <pattern>

Uses glob patterns:

# All text files
avfs find / -n "*.txt"

# Files starting with "test"
avfs find /src -n "test*"

# Single character wildcard
avfs find / -n "file?.txt"  # file1.txt, fileA.txt, etc.

Find by Type

# Files only
avfs find / -t f

# Directories only
avfs find / -t d

Find by Size

# Files larger than 10MB
avfs find / --min-size 10485760

# Files smaller than 1KB
avfs find / --max-size 1024

Find by Tag

avfs find / --tag important
avfs find / --tag work --tag urgent  # Multiple tags

Find by Metadata

avfs find / --meta author="Jane Doe"

Combining Conditions

# Large Rust files
avfs find /src -n "*.rs" --min-size 10240

# Files with specific tag
avfs find /docs --tag important

Performance Tips

Rebuild Index

If search seems slow or incomplete:

avfs search --rebuild

Search Large Vaults

For very large vaults:

# Limit results
avfs search --limit 100 "pattern"

# Search specific directory
avfs search "pattern" /relevant/directory/

# Use grep for targeted search
avfs grep "pattern" /specific/file.txt

Output Formats

Standard Output

$ avfs grep "error" /logs/
/logs/app.log:15:Error: Connection failed
/logs/app.log:23:error handling exception

JSON Output

$ avfs grep --json "error" /logs/
{
  "matches": [
    {
      "path": "/logs/app.log",
      "line": 15,
      "content": "Error: Connection failed"
    }
  ]
}

Integration Examples

Find and Process

# Find all Python files
avfs find /src -n "*.py" | while read file; do
    echo "Processing $file"
    avfs cat "$file" | wc -l
done

Search with Tags

# Search only in tagged files
avfs find / --tag code | while read file; do
    avfs grep "TODO" "$file"
done

Export Search Results

# Create report of all TODOs
avfs grep "TODO|FIXME" /src/ > ~/todos-report.txt