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
Basic File Reading
Basic File Reading
Copy
# Read entire file
/read src/components/Button.tsx
# Read specific lines (useful for large files)
/read src/utils/helpers.ts 1-50
/read package.json 10-20
# Read with syntax highlighting
/read src/api/auth.js --highlight
Copy
š src/components/Button.tsx (45 lines)
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
1ā import React from 'react';
2ā import { ButtonProps } from '../types/components';
3ā import styles from './Button.module.css';
4ā
5ā export const Button: React.FC<ButtonProps> = ({
6ā children,
7ā variant = 'primary',
8ā size = 'medium',
9ā disabled = false,
10ā onClick,
11ā ...props
12ā }) => {
13ā return (
14ā <button
15ā className={`${styles.button} ${styles[variant]} ${styles[size]}`}
16ā disabled={disabled}
17ā onClick={onClick}
18ā {...props}
19ā >
20ā {children}
21ā </button>
22ā );
23ā };
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Advanced Reading Options
Advanced Reading Options
Copy
# Read multiple files
/read src/components/*.tsx
/read "src/**/*.ts" --recursive
# Read with filters
/read src/api/auth.js --functions-only
/read src/types/index.ts --exports-only
/read src/components/Form.tsx --comments-only
# Read file metadata
/read src/main.ts --info
Copy
š File Information: src/main.ts
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Size: 2.3 KB (2,345 bytes)
Lines: 87 (72 code, 12 comments, 3 blank)
Created: 2024-03-15 10:30:22
Modified: 2024-03-20 14:45:33
Type: TypeScript
Encoding: UTF-8
Dependencies: 8 imports
Exports: 3 functions, 1 interface
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Binary and Image Files
Binary and Image Files
Copy
# View image files (shows file info + opens in viewer)
/read assets/logo.png
/read public/images/hero.jpg
# View binary file information
/read dist/app.js --binary-info
# View package contents
/read package-lock.json --summary
/ls - List Directory Contents
- Basic Listing
- Advanced Listing
- Statistics and Analysis
Copy
# List current directory
/ls
# List specific directory
/ls src/
/ls src/components/
# List with details
/ls src/ --details
/ls --all # Include hidden files
Copy
š 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 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Copy
# Tree view
/ls src/ --tree
/ls --tree --depth 3
# Filter by type
/ls src/ --type typescript
/ls assets/ --type image
/ls --type directory
# Sort options
/ls src/ --sort size
/ls src/ --sort modified
/ls src/ --sort name
Copy
š src/
āāā š components/
ā āāā š Button.tsx
ā āāā š Form.tsx
ā āāā š Modal.tsx
ā āāā š ui/
ā āāā š Input.tsx
ā āāā š Select.tsx
āāā š hooks/
ā āāā š useAuth.ts
ā āāā š useApi.ts
ā āāā š useLocalStorage.ts
āāā š pages/
ā āāā š Home.tsx
ā āāā š Login.tsx
ā āāā š Dashboard.tsx
āāā š App.tsx
Copy
# Directory statistics
/ls src/ --stats
# File type breakdown
/ls --analysis
# Large files identification
/ls --large-files
Copy
š Directory Analysis: src/
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Total Items: 47 files, 12 directories
Total Size: 234.5 KB
File Types:
āāā TypeScript: 32 files (68%)
āāā CSS: 8 files (17%)
āāā JSON: 4 files (9%)
āāā Other: 3 files (6%)
Largest Files:
āāā App.tsx (8.3 KB)
āāā main.css (6.1 KB)
āāā types/api.ts (4.7 KB)
Last Modified: 30 minutes ago
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Write Operations
/write - Create/Modify Files
File Creation
File Creation
Copy
# Create new file with content
/write src/utils/logger.ts "export const logger = console;"
# Create file with multi-line content
/write src/components/Header.tsx """
import React from 'react';
export const Header: React.FC = () => {
return (
<header>
<h1>My App</h1>
</header>
);
};
"""
# Create from template
/write src/pages/NewPage.tsx --template react-page
Copy
š File Creation Request
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Operation: Create new file
Path: src/utils/logger.ts
Size: 145 bytes
Type: TypeScript
Content Preview:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā export const logger = { ā
ā info: (msg: string) => console. ā
ā error: (msg: string) => console. ā
ā warn: (msg: string) => console. ā
ā }; ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Impact Assessment:
āāā New dependency: None
āāā Breaking changes: None
āāā Security risk: Low
āāā Test coverage: Manual testing required
Approve file creation? (y/n/edit)
File Modification
File Modification
Copy
# Overwrite entire file
/write src/config/api.ts "export const API_URL = 'https://api.example.com';"
# Append to file
/write src/types/user.ts --append "export interface Admin extends User { role: 'admin' }"
# Insert at specific line
/write src/main.ts --insert-at 5 "import './styles/global.css';"
# Replace specific content
/write src/config/database.ts --replace "localhost" "production-db.example.com"
Copy
š File Modification Request
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Operation: Modify existing file
Path: src/config/api.ts
Changes:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā - export const API_URL = 'http://lo ā
ā + export const API_URL = 'https://a ā
ā ā
ā + export const API_TIMEOUT = 5000; ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Impact: Production configuration change
Risk Level: MEDIUM
Backup created: .nikcli/backups/api.ts.20240320-143022
Approve changes? (y/n/review)
Batch File Operations
Batch File Operations
Copy
# Create multiple files from template
/write-batch src/components/ --template component --names "Modal,Tooltip,Spinner"
# Update multiple files with same change
/write-batch "src/**/*.ts" --replace "old-import" "new-import"
# Create file structure
/write-structure """
src/
components/
Button.tsx: [react-component template]
Input.tsx: [react-component template]
hooks/
useAuth.ts: [custom-hook template]
types/
index.ts: [type-definitions template]
"""
/edit - Interactive File Editing
- In-place Editing
- Guided Editing
Copy
# 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
Copy
š 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)
Copy
# AI-assisted editing
/edit src/api/auth.ts --guided
# Fix specific issues
/edit src/components/Form.tsx --fix typescript-errors
/edit src/styles/app.css --fix lint-warnings
# Apply specific transformations
/edit src/utils/helpers.ts --transform "convert to arrow functions"
Copy
šÆ Guided Edit: src/api/auth.ts
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Analyzing file for improvement opportunities...
Found Issues:
āāā ā ļø Line 23: Missing error handling
āāā ā ļø Line 31: Unused import statement
āāā š” Line 45: Can optimize async/await pattern
āāā š” Line 52: Add type annotation for better safety
Apply suggested fixes? (y/n/selective)
> selective
Select fixes to apply:
[ā] Add error handling (Line 23)
[ā] Remove unused import (Line 31)
[ ] Optimize async pattern (Line 45)
[ā] Add type annotation (Line 52)
Apply selected fixes? (y/n)
Search Operations
/search or /grep - Content Search
Basic Search
Basic Search
Copy
# Search for text in files
/search "function handleLogin"
/grep "interface User"
# Search in specific directories
/search "useState" src/components/
/grep "TODO" src/ --recursive
# Case-insensitive search
/search "react" --ignore-case
/grep "API_KEY" --case-insensitive
Copy
š Search Results: "useState"
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Found 12 matches in 8 files
š src/components/LoginForm.tsx (3 matches)
āāā Line 8: const [email, setEmail] = useState('');
āāā Line 9: const [password, setPassword] = useState('');
āāā Line 10: const [loading, setLoading] = useState(false);
š src/components/UserProfile.tsx (2 matches)
āāā Line 15: const [user, setUser] = useState<User | null>(null);
āāā Line 16: const [editing, setEditing] = useState(false);
š src/hooks/useAuth.ts (4 matches)
āāā Line 5: const [token, setToken] = useState<string | null>(null);
āāā Line 6: const [user, setUser] = useState<User | null>(null);
āāā Line 7: const [loading, setLoading] = useState(true);
āāā Line 8: const [error, setError] = useState<string | null>(null);
Show more results? (y/n/open)
Advanced Search Patterns
Advanced Search Patterns
Copy
# Regular expression search
/search "function\s+\w+\(" --regex
/grep "export\s+(const|function)\s+\w+" --regex
# Search by file type
/search "console.log" --type typescript
/grep "margin:" --type css
# Exclude patterns
/search "debug" --exclude "*.test.ts" --exclude "node_modules"
# Search with context
/search "error" --context 3 # 3 lines before and after
/grep "TODO" --before 2 --after 1
Structured Search
Structured Search
Copy
# Search for specific code patterns
/search --pattern "react-component-definition"
/search --pattern "function-with-async"
/search --pattern "import-statement"
# Search for dependencies
/search --dependencies "react"
/search --unused-imports
/search --unused-variables
# Search for security issues
/search --security-patterns
/search --potential-vulnerabilities
Copy
š Pattern Search: "react-component-definition"
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Found 15 React components
š src/components/Button.tsx
āāā Component: Button (Functional Component)
āāā Props: ButtonProps interface
āāā Exports: Named export
āāā Uses: React.FC pattern
š src/components/Modal.tsx
āāā Component: Modal (Functional Component)
āāā Props: ModalProps interface
āāā Exports: Default export
āāā Uses: forwardRef pattern
š src/pages/Dashboard.tsx
āāā Component: Dashboard (Functional Component)
āāā Props: No props interface
āāā Exports: Default export
āāā Uses: Basic function declaration
Analysis Summary:
āāā Functional Components: 15 (100%)
āāā Class Components: 0 (0%)
āāā Components with Props: 12 (80%)
āāā Components with TypeScript: 15 (100%)
/search (files) - Find Files by Name
- Basic File Finding
- Advanced Search
Copy
# Find files by name (using glob)
/search "Button.tsx"
/search "*.css"
/search "test.*"
# Search in specific directories
/search "*.ts" src/
/search "package.json" --recursive
# Find by partial name (content grep supports patterns)
/search "component" --ignore-case
Copy
š 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
Copy
# Content options and filters
/search --regex "function\\s+\\w+\("
/search "useState" --type typescript
# Exclude patterns
/search "*.js" --exclude node_modules --exclude dist
# Execute related commands manually with /run
/run "npm test"
/run "eslint src/**/*.tsx"
Security and Permissions
File Access Control
Permission Levels
Permission Levels
Copy
# Check current permissions
/permissions
# View file-specific permissions
/permissions src/config/secrets.ts
# Request elevated permissions
/request-permission write-config
/request-permission read-sensitive
Copy
š File Operation Permissions
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Current Security Level: š”ļø Default
Read Permissions:
āāā ā
Source code files (src/*)
āāā ā
Configuration files (*.json, *.yaml)
āāā ā
Documentation (*.md, docs/*)
āāā ā ļø Environment files (.env.*) - Approval required
āāā ā System files (/etc, /usr) - Blocked
Write Permissions:
āāā ā
Source code files (src/*)
āāā ā ļø Configuration files - Approval required
āāā ā ļø Package files (package.json) - Approval required
āāā ā Environment files - Blocked in default mode
āāā ā System files - Always blocked
Special Operations:
āāā ā
File backups - Automatic
āāā ā
Syntax validation - Automatic
āāā ā ļø Bulk operations - Approval required
āāā ā ļø Destructive operations - Approval required
Approval Workflows
Approval Workflows
Copy
š”ļø Security Approval Required
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Operation: Modify configuration file
File: package.json
Risk Level: MEDIUM
Requested Changes:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā + "express": "^4.18.2", ā
ā + "cors": "^2.8.5", ā
ā + "dotenv": "^16.0.3" ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Impact Analysis:
āāā New dependencies: 3 packages
āāā Security scan: ā
No vulnerabilities
āāā Bundle size impact: +245 KB
āāā Breaking changes: None detected
āāā Backup created: ā
Options:
[A] Approve and continue
[R] Reject operation
[M] Modify request
[I] Show detailed impact analysis
Choice: _
Backup and Recovery
Backup and Recovery
Copy
# Manual backup
/backup src/components/
/backup package.json
# List backups
/backups list
/backups list --recent
# Restore from backup
/restore package.json
/restore src/components/Button.tsx --version 2024-03-20-14:30
# Compare with backup
/diff-backup src/config/api.ts
Copy
š¦ Backup Management
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Auto-backup: ā
Enabled (before destructive operations)
Backup Location: .nikcli/backups/
Retention: 30 days (configurable)
Recent Backups:
āāā 2024-03-20 14:30 - package.json (dependency update)
āāā 2024-03-20 13:45 - src/api/auth.ts (refactoring)
āāā 2024-03-20 12:15 - src/components/ (batch update)
āāā 2024-03-20 10:30 - .env.example (configuration)
āāā 2024-03-19 16:20 - src/types/user.ts (type changes)
Storage Used: 2.3 MB / 100 MB limit
Commands:
[L] List all backups
[R] Restore specific backup
[C] Clean old backups
[S] Show backup settings
Performance and Optimization
Efficient File Operations
Batch Operations
Process multiple files efficiently
Copy
# 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
Copy
# 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
- File Caching
- Search Optimization
Copy
# 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
Copy
# Index files for faster search
/index src/ --build
/index update
# Search with index
/search "function" --use-index
# Index statistics
/index 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
Terminal Operations
Learn command execution and terminal integration
Project Operations
Master project-level operations and management
Advanced Configuration
Configure file operation security and preferences
Workflow Patterns
Integrate file operations into development workflows
File operations in NikCLI respect security policies and may require approval for sensitive files. Always review changes before approving destructive operations.
