File Operations Overview

NikCLI provides secure, powerful file system operations with built-in safety measures and intelligent context awareness. All file operations respect security policies and provide approval workflows when needed.

Read Operations

View file contents and directory listings

Write Operations

Create and modify files with approval workflows

Search Operations

Find files and search content across your project

Batch Operations

Perform operations on multiple files efficiently

Read Operations

/read - Read File Contents

/ls - List Directory Contents

# List current directory
/ls

# List specific directory
/ls src/
/ls src/components/

# List with details
/ls src/ --details
/ls --all  # Include hidden files
Output Example:
📁 src/ (12 items)
┌─────────────────────────────────────────────────────────┐
│ Name                Type        Size      Modified       │
├─────────────────────────────────────────────────────────┤
│ 📁 components/      Directory   -         2 hours ago    │
│ 📁 hooks/          Directory   -         1 day ago      │
│ 📁 pages/          Directory   -         3 hours ago    │
│ 📁 services/       Directory   -         2 days ago     │
│ 📁 types/          Directory   -         1 day ago      │
│ 📁 utils/          Directory   -         5 hours ago    │
│ 📄 App.tsx         TypeScript  3.2 KB    30 min ago     │
│ 📄 index.tsx       TypeScript  1.8 KB    2 hours ago    │
│ 📄 main.css        CSS         2.1 KB    1 day ago      │
│ 📄 vite-env.d.ts   TypeScript  158 B     1 week ago     │
└─────────────────────────────────────────────────────────┘

Write Operations

/write - Create/Modify Files

/edit - Interactive File Editing

# Open file in system editor
/edit src/components/App.tsx

# Edit specific lines
/edit src/config/settings.ts --lines 10-20

# Edit with specific editor
/edit src/styles/main.css --editor code
/edit README.md --editor vim
Interactive Editing Session:
📝 Interactive Edit: src/components/App.tsx
───────────────────────────────────────
Opening in VS Code...

⏳ Waiting for editor to close...

✅ File modified (3 changes detected)

Changes Summary:
├── Line 15: Added import statement
├── Line 23: Modified component props
└── Line 31: Added new method

Review changes? (y/n/diff)

Search Operations

/find - Find Files by Name

# Find files by name
/find "Button.tsx"
/find "*.css"
/find "test.*"

# Find in specific directories
/find "*.ts" src/
/find "package.json" --recursive

# Find by partial name
/find "*component*" --ignore-case
Find Results:
📁 Find Results: "*.tsx"
───────────────────────────────────────
Found 23 files

📄 src/components/
├── Button.tsx (2.3 KB)
├── Modal.tsx (4.1 KB)
├── Form.tsx (5.2 KB)
├── Header.tsx (1.8 KB)
└── Navigation.tsx (3.4 KB)

📄 src/pages/
├── Home.tsx (6.7 KB)
├── Login.tsx (3.9 KB)
├── Dashboard.tsx (8.2 KB)
└── Profile.tsx (4.5 KB)

📄 src/
├── App.tsx (2.1 KB)
└── main.tsx (0.8 KB)

Total: 23 files, 52.9 KB

Security and Permissions

File Access Control

Performance and Optimization

Efficient File Operations

Batch Operations

Process multiple files efficiently
# Batch read
/read src/components/*.tsx --batch

# Batch search
/search "useState" src/ --batch --parallel

# Batch write with template
/write-batch --template component --count 5

Streaming Operations

Handle large files efficiently
# Stream large file content
/read logs/app.log --stream

# Tail file content
/tail logs/error.log --follow

# Process in chunks
/search "error" logs/ --chunk-size 1MB

Caching and Optimization

# Enable file content caching
nikcli config set file-cache.enabled true
nikcli config set file-cache.max-size 100MB

# Clear file cache
/cache clear --files
/cache clear --search-results

# Cache statistics
/cache stats

Best Practices

Safety First

Always prioritize data safety
  • Review changes before approval
  • Use backups for important files
  • Test in development first
  • Understand permission implications

Efficiency

Optimize your file operations
  • Use batch operations for multiple files
  • Leverage caching for repeated operations
  • Use specific paths to reduce search scope
  • Enable indexing for frequent searches

Organization

Maintain clean file structure
  • Use consistent naming conventions
  • Organize files logically
  • Regular cleanup of temporary files
  • Document file organization patterns

Collaboration

Team-friendly practices
  • Document file changes clearly
  • Use meaningful commit messages
  • Coordinate on file modifications
  • Share file operation patterns

Next Steps

File operations in NikCLI respect security policies and may require approval for sensitive files. Always review changes before approving destructive operations.