# 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 ```bash ls -la "path/to/file.md" ``` **Output shows:** - File permissions - Owner - Size in bytes - **Modification timestamp** (critical!) - Filename **Example:** ```bash ls -la "_Nakul/TEST Obsidian Closed Test.md" # Output: -rw-r--r--@ 1 user staff 720 Nov 8 14:45 TEST... ``` ### Read File Contents ```bash cat "path/to/file.md" ``` **Use when:** You want to see exact contents including frontmatter **Pro tip:** Use `head` for just the first lines: ```bash head -15 "path/to/file.md" # First 15 lines (covers frontmatter) ``` ### Detailed File Metadata **macOS:** ```bash stat -f "%Sm - %N" "path/to/file.md" ``` **Linux:** ```bash stat --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 ```bash ls -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:** ```bash grep "<%" "path/to/file.md" ``` **Output:** - If empty: Templates were processed ✅ - If matches found: Literal syntax remains ❌ ### 2. Comparing File Versions **Before editing:** ```bash cat "file.md" > /tmp/before.txt ``` **After editing:** ```bash cat "file.md" > /tmp/after.txt diff /tmp/before.txt /tmp/after.txt ``` Shows exact changes made. ### 3. Watching File Changes in Real-Time **macOS:** ```bash fswatch -o "path/to/file.md" | xargs -n1 -I{} date ``` **Linux:** ```bash inotifywait -m "path/to/file.md" ``` Prints timestamp every time file is modified. ### 4. Finding Recently Modified Files ```bash find . -name "*.md" -mtime -1 ``` Lists all `.md` files modified in last 24 hours. **More specific:** ```bash find . -name "*.md" -mmin -10 ``` Modified in last 10 minutes. ## Debugging Frontmatter Issues ### Check for Invalid YAML ```bash head -20 "file.md" | grep -E "^[a-z_]+:" ``` Shows all frontmatter keys. Look for: - Missing colons - Inconsistent indentation - Unexpected characters ### Verify Frontmatter Values ```bash grep "^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:** ```bash stat -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:** ```bash stat -f "%Sc" "file.md" ``` ## Proving File Existence Order **Scenario:** You want to prove File A existed before File B. ```bash ls -lt file-a.md file-b.md ``` Older file appears lower in output. **Or compare directly:** ```bash if [ "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 ```bash ls -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 ```bash find . -name "*.md" -newermt "today" | wc -l ``` ### Find Files with Specific Frontmatter ```bash grep -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]]