How to Use rsync -a Flag While Excluding Symbolic Links: A Technical Deep Dive


1 views

When working with rsync, the -a (archive) flag is one of the most commonly used options, as it conveniently bundles several important preservation flags:

-rlptgoD (recursive, links, perms, times, group, owner, devices)

However, there are scenarios where we want most archive functionality except for following symbolic links. While we could manually specify -rptgoD, this becomes tedious in scripts and command-line operations.

The most elegant approach combines the archive flag with explicit link handling:

rsync -a --no-links source/ destination/

This maintains all archive functionality while preventing symbolic links from being copied. The --no-links option tells rsync to treat symlinks as regular files.

Here are some real-world use cases with different variations:

# Basic directory sync without symlinks
rsync -a --no-links /source/project/ /backup/project/

# Remote sync example
rsync -a --no-links -e ssh user@remote:/var/www/ /local/backup/

# With additional exclude patterns
rsync -a --no-links --exclude='*.tmp' src/ dst/

For those who frequently need this combination, consider creating a shell alias:

alias rsync-no-links="rsync -a --no-links"

Or for bash users, add to your .bashrc:

function rcp() {
    rsync -a --no-links "$@"
}

The -a (archive) flag in rsync is indeed equivalent to -rlptgoD, where the -l option specifically handles symbolic link preservation. Many developers find themselves needing archive behavior without link replication, particularly when:

  • Migrating data between different filesystem types
  • Creating portable backups
  • Maintaining strict file hierarchy integrity

Instead of typing out -rptgoD each time (which omits -l), you can use:

rsync -a --no-links source/ destination/

This maintains all other archive mode benefits while explicitly disabling symbolic link copying. The --no-links option works with both local and remote transfers.

Here's how this approach solves real-world problems:

# Backup web assets without following symlinks
rsync -a --no-links --delete /var/www/ user@backup:/backups/www/

# Mirror a development directory structure
rsync -a --no-links --exclude='node_modules/' ./project/ /mnt/build/

The --no-links option combines effectively with other common rsync parameters:

# Dry-run with verbose output
rsync -avn --no-links src/ dst/

# With bandwidth limiting
rsync -a --no-links --bwlimit=1000 /data/ remote:/backup/data/

In containerized environments where symlinks might point to host paths, or when transferring data between Windows and Unix systems, skipping symbolic links prevents:

  • Broken link references
  • Security issues from unintended path resolution
  • Storage bloat from duplicate content

For frequent use, create a shell alias:

# Add to your .bashrc or .zshrc
alias rsync-no-links='rsync -a --no-links'

Then use simply:

rsync-no-links source/ destination/