Verifying File Changes with Terminal Inspection
Verifying File Changes with Terminal Inspection
The Schrödinger's Cat Problem
When working with files in Obsidian (or any application that watches the filesystem), you might wonder: "Did this file exist before I opened the app, or did opening the app create it?"
This is similar to Schrödinger's cat - the act of observation (opening Obsidian) might affect the state you're trying to verify.
Solution: Use terminal commands to inspect files BEFORE opening the application.
Essential Verification Commands
Check If File Exists
bashls -la "path/to/file.md"
Output shows:
- File permissions
- Owner
- Size in bytes
- Modification timestamp (critical!)
- Filename
Example:
bashls -la "_Nakul/TEST Obsidian Closed Test.md" # Output: -rw-r--r--@ 1 user staff 720 Nov 8 14:45 TEST...
Read File Contents
bashcat "path/to/file.md"
Use when: You want to see exact contents including frontmatter
Pro tip: Use head for just the first lines:
bashhead -15 "path/to/file.md" # First 15 lines (covers frontmatter)
Detailed File Metadata
macOS:
bashstat -f "%Sm - %N" "path/to/file.md"
Linux:
bashstat --format="%y - %n" "path/to/file.md"
Output shows:
- Full modification timestamp with seconds
- Filename
Example output:
Nov 8 14:45:32 2025 - /path/to/file.md
Check Multiple Files at Once
bashls -ltr _Nakul/TEST*.md
Flags explained:
-l= long format (detailed)-t= sort by time-r= reverse order (newest last)
Use when: Checking creation order of multiple test files
Verification Workflow
Scenario: AI Agent Created a File
Step 1: AI creates file via terminal/API
Step 2: Verify BEFORE opening Obsidian:
bash# Navigate to vault cd "/path/to/vault" # Check file exists and timestamp ls -la "path/to/new-file.md" # Read contents to verify frontmatter head -15 "path/to/new-file.md" # Get detailed timestamp stat -f "%Sm" "path/to/new-file.md"
Step 3: Note the timestamp (e.g., "14:45:32")
Step 4: Open Obsidian
Step 5: Verify file appears with same content
Result: You've proven the file existed before Obsidian opened it.
Common Use Cases
1. Verifying Template Processing
Question: Did AI replace Templater syntax or leave it literal?
Command:
bashgrep "<%" "path/to/file.md"
Output:
- If empty: Templates were processed ✅
- If matches found: Literal syntax remains ❌
2. Comparing File Versions
Before editing:
bashcat "file.md" > /tmp/before.txt
After editing:
bashcat "file.md" > /tmp/after.txt diff /tmp/before.txt /tmp/after.txt
Shows exact changes made.
3. Watching File Changes in Real-Time
macOS:
bashfswatch -o "path/to/file.md" | xargs -n1 -I{} date
Linux:
bashinotifywait -m "path/to/file.md"
Prints timestamp every time file is modified.
4. Finding Recently Modified Files
bashfind . -name "*.md" -mtime -1
Lists all .md files modified in last 24 hours.
More specific:
bashfind . -name "*.md" -mmin -10
Modified in last 10 minutes.
Debugging Frontmatter Issues
Check for Invalid YAML
bashhead -20 "file.md" | grep -E "^[a-z_]+:"
Shows all frontmatter keys. Look for:
- Missing colons
- Inconsistent indentation
- Unexpected characters
Verify Frontmatter Values
bashgrep "^created:" "file.md" grep "^slug:" "file.md"
Extract specific frontmatter fields.
Advanced (using yq):
bash# Install: brew install yq yq eval '.created' "file.md"
Parses YAML properly.
File Timestamp Types
Unix tracks three timestamps:
1. Modification Time (mtime)
When file content was last changed.
Check:
bashstat -f "%Sm" "file.md" # macOS stat --format="%y" "file.md" # Linux
2. Access Time (atime)
When file was last read.
Note: Often disabled on modern systems for performance.
3. Change Time (ctime)
When file metadata (permissions, ownership) changed.
macOS:
bashstat -f "%Sc" "file.md"
Proving File Existence Order
Scenario: You want to prove File A existed before File B.
bashls -lt file-a.md file-b.md
Older file appears lower in output.
Or compare directly:
bashif [ "file-a.md" -ot "file-b.md" ]; then echo "file-a.md is older" else echo "file-b.md is older" fi
Best Practices
1. Document Verification Steps
When testing, save your commands:
bash# Create verification script echo "ls -la _Nakul/TEST*.md" > verify.sh echo "head -15 _Nakul/TEST*.md" >> verify.sh chmod +x verify.sh
2. Use Absolute Paths
Avoid confusion:
bash# Good ls -la "/Users/you/vault/file.md" # Bad (depends on current directory) ls -la "file.md"
3. Capture Output for Records
bashls -la "file.md" > verification-$(date +%Y%m%d-%H%M%S).txt
Creates timestamped proof.
4. Check Before and After
Always verify state before making changes:
bash# Before ls -la "file.md" # Make changes (AI edit, manual edit, etc.) # After ls -la "file.md"
Compare timestamps to confirm changes occurred.
Related Commands
Watch Directory for New Files
bash# macOS fswatch -0 /path/to/vault | xargs -0 -n1 echo "File changed:" # Linux inotifywait -m -r /path/to/vault
Count Files Created Today
bashfind . -name "*.md" -newermt "today" | wc -l
Find Files with Specific Frontmatter
bashgrep -l "^slug: xyz" *.md
Finds all files with slug: xyz.
Troubleshooting
Problem: stat command not found
Solution: Use ls -l instead (less detailed but universal)
Problem: Timestamps don't match across systems Solution: Time zones! Convert to UTC or specify timezone explicitly
Problem: File appears in Obsidian but not terminal Solution: Check if Obsidian is showing a cached view; check file path carefully
Problem: Terminal shows file but Obsidian doesn't Solution: Refresh Obsidian vault (Cmd+R or restart)
Related
- Template Systems - Templater vs AI Agent Creation
- Managing Long Frontmatter