Skip to content

Symlink Modes

Adrian Thomas edited this page Oct 2, 2025 · 5 revisions

Symlink Modes

symlinkit 2.0 supports four CRUD operations: Create, Overwrite, Merge, and Delete. Understanding when to use each mode is key to effective symlink management.


Create Mode (-c)

Create a new symlink safely without overwriting existing files.

Behavior

  • Succeeds: If destination doesn't exist
  • Fails: If destination already exists (file or directory)
  • Safe: Never overwrites existing content

Usage

# Create symlink to file
symlinkit -c ~/dotfiles/.bashrc ~/.bashrc

# Create symlink to directory
symlinkit -c ~/dotfiles/nvim ~/.config/nvim

# Preview first
symlinkit --dry-run -c ~/source ~/dest

When to Use

  • First-time setup
  • When you want to prevent accidental overwrites
  • Testing symlink creation
  • Setting up new configurations

Recursive Create (-cr)

Behaves identically to Merge Mode (-m):

# These are equivalent
symlinkit -cr ~/dotfiles ~/.config
symlinkit -m ~/dotfiles ~/.config

Overwrite Mode (-o)

Replace existing files or directories with symlinks.

Behavior

  • Removes existing file/directory at destination
  • Creates symlink in its place
  • Destructive: Original content is deleted (use --dry-run first!)

Usage

# Replace file with symlink
symlinkit -o ~/dotfiles/.zshrc ~/.zshrc

# Replace directory with symlink
symlinkit -o ~/dotfiles/nvim ~/.config/nvim

# ALWAYS preview first!
symlinkit --dry-run -o ~/source ~/dest

When to Use

  • Replacing existing configs with symlinked versions
  • Converting regular files to symlinks
  • When you're certain you want to overwrite

Safety Warning

⚠️ Overwrite mode is destructive! Always use --dry-run first:

# Step 1: Preview
symlinkit --dry-run -o ~/dotfiles/.vimrc ~/.vimrc

# Step 2: If looks good, apply
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc

Recursive Overwrite (-or)

Recursively creates symlinks with interactive prompts for conflicts:

symlinkit -or ~/dotfiles ~/.config

For each conflict, you'll be prompted:

⚠️  Conflict: ~/.config/existing.txt exists.
[s]kip / [o]verwrite / [a]ll overwrite / [c]ancel >

Merge Mode (-m)

Recursively symlink directory contents into destination.

Behavior

  • Traverses source directory recursively
  • Creates symlinks for each file/subdirectory
  • Preserves destination directory structure
  • Interactive prompts for conflicts

Usage

# Merge dotfiles into home directory
symlinkit -m ~/dotfiles/.config ~/.config

# Preview merges
symlinkit --dry-run -m ~/source ~/dest

Example Scenario

Before:

~/dotfiles/scripts/
  ├── backup.sh
  └── deploy.sh

~/bin/
  └── old.sh

Command:

symlinkit -m ~/dotfiles/scripts ~/bin

After:

~/bin/
  ├── backup.sh -> ~/dotfiles/scripts/backup.sh
  ├── deploy.sh -> ~/dotfiles/scripts/deploy.sh
  └── old.sh (preserved)

Conflict Handling

When a file already exists at the destination:

⚠️  Conflict: ~/bin/backup.sh exists.
[s]kip / [o]verwrite / [a]ll overwrite / [c]ancel >

Options:

  • s - Skip this file
  • o - Overwrite this file with symlink
  • a - Overwrite all remaining conflicts
  • c - Cancel operation

When to Use

  • Dotfiles management
  • Distributing scripts across directories
  • Gradually symlinking configs
  • Preserving existing files while adding new symlinks

Delete Mode (-d)

Remove symlinks safely without affecting their targets.

Behavior

  • Removes the symlink
  • Preserves the target file/directory
  • Safe: Only deletes symlinks, never the source

Usage

# Delete single symlink
symlinkit -d ~/.config/nvim

# Preview deletion
symlinkit --dry-run -d ~/.bashrc

Safety Feature

Only symlinks can be deleted:

# This file is a symlink
symlinkit -d ~/.zshrc
# ✅ Deleted successfully

# This file is NOT a symlink
symlinkit -d ~/real-file.txt
# ❌ Error: Not a symlink

Recursive Delete (-dr)

Interactively delete all symlinks in a directory:

symlinkit -dr ~/bin

For each symlink found:

~/.local/bin/script.sh -> ~/dotfiles/scripts/script.sh
[d]elete / [a]ll delete / [s]kip / [q]uit >

Options:

  • d - Delete this symlink
  • a - Delete all remaining symlinks
  • s - Skip this symlink
  • q - Quit and exit

When to Use

  • Cleaning up symlinks
  • Removing outdated configurations
  • Undoing symlink operations
  • Auditing symlink usage

Mode Comparison

Mode Flag Overwrites? Recursive Use Case
Create -c No -cr (= merge) Safe initial setup
Overwrite -o Yes -or (prompts) Replace existing files
Merge -m Prompts Yes Dotfiles management
Delete -d N/A -dr (prompts) Clean up symlinks

Dry Run Mode

Always test with --dry-run first!

# Preview create
symlinkit --dry-run -c ~/source ~/dest

# Preview overwrite
symlinkit --dry-run -o ~/source ~/dest

# Preview merge
symlinkit --dry-run -m ~/source ~/dest

# Preview delete
symlinkit --dry-run -d ~/symlink

Best Practices

1. Always Dry Run Destructive Operations

# GOOD: Check first
symlinkit --dry-run -o ~/dotfiles/.vimrc ~/.vimrc
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc

# BAD: Direct overwrite
symlinkit -o ~/dotfiles/.vimrc ~/.vimrc  # RISKY!

2. Use Create for New Setups

# First time setup
symlinkit -c ~/dotfiles/.bashrc ~/.bashrc

3. Use Merge for Dotfiles

# Gradually add symlinks
symlinkit -m ~/dotfiles ~/.config

4. Use Delete to Undo

# Remove symlinks cleanly
symlinkit -d ~/.config/nvim

Next Steps