Excluding Certain Directories and File Types during Sync in Tech Support

Abstract: Exclude specific directories and file types during rsync synchronization to optimize bandwidth and reduce transfer time.

Created: 2026-09-10 by

Use the --exclude flag in rsync to filter specific directories and file types during synchronization. This command-line tool allows precise control over which files are transferred, ensuring that large or unnecessary data like Project Gutenberg's library archives are skipped. By defining patterns for exclusion, you optimize bandwidth and reduce sync time significantly.

Understanding the Exclusion Syntax

The core mechanism for excluding files in rsync relies on pattern matching rules. These rules are applied sequentially, meaning the order of your exclude statements can matter if there are conflicting includes and excludes. The basic syntax involves using the --exclude=PATTERN option followed by a glob-style pattern. For example, to exclude all files ending in .tmp, you would use --exclude="*.tmp". Patterns can match against the full path of the file or just the filename depending on whether a slash is included. If the pattern contains no slashes, it matches the last component of the file name. If it contains slashes, it matches against the entire path relative to the source directory. This distinction is crucial when dealing with nested directory structures common in large libraries.

Common Pattern Types

  • Simple Extensions: Use *.log to exclude all log files regardless of their location.
  • Directory Names: Use /cache/ to exclude any directory named cache at any level.
  • Specific Files: Use readme.txt to exclude exactly that file wherever it appears.

Excluding Directories Efficiently

When synchronizing large datasets, entire directories often need to be skipped to save space and time. In the context of managing a digital library such as Project Gutenberg, you might want to exclude temporary working folders or metadata directories that do not contain actual text files. To exclude a directory, specify its name in the exclude pattern. For instance, if your project structure includes a .git folder or a node_modules directory, these should typically be excluded. The command would look like this: rsync -av --exclude='.git' --exclude='node_modules' /source/ /destination/. Note that including a trailing slash in the pattern /dir/ ensures that only directories named dir are matched, not files with similar names. This approach prevents the transfer of binary dependencies or version control history, which are irrelevant for most content distribution scenarios. It also reduces the load on network resources, making the sync process faster and more reliable.

Filtering Specific File Types

Beyond directories, filtering by file extension is essential for maintaining clean transfers. You may wish to exclude compiled binaries, image assets, or temporary backup files from your synchronization process. Using wildcards allows you to target multiple file types simultaneously. To exclude various media formats, you can chain multiple exclude options. For example: rsync -av --exclude="*.jpg" --exclude="*.png" --exclude="*.mp4" /source/ /dest/. This ensures that only the desired text-based or code-based files are transferred. When dealing with Project Gutenberg's library, you might specifically want to exclude HTML files if you are only interested in plain text versions, or vice versa. It is important to test these patterns on a small subset first to ensure they behave as expected. Misconfigured patterns can lead to either too much data being transferred or critical files being accidentally omitted.

Practical Application with Project Gutenberg

Project Gutenberg offers millions of public domain texts, but downloading everything can be inefficient. If you are syncing a local mirror or updating a personal archive, you likely do not need every single file type. Many entries come with associated metadata, cover images, or XML files that may not be necessary for your primary use case. You can create a script that runs rsync with a comprehensive list of excludes. This script can include exclusions for *.xml, *.html, and *.zip if you prefer to work only with raw text files. Additionally, excluding directories like images/ or data/ can further streamline the process. By customizing your exclusion list, you tailor the sync operation to your specific needs. This method is particularly useful for users who want to maintain a lightweight, searchable database of texts without the bloat of multimedia assets.

Troubleshooting Common Issues

Even with correct syntax, issues can arise during synchronization. One common problem is that excluded files still appear in the destination because they were already present from a previous sync. Rsync does not delete files that are not part of the current transfer unless you explicitly tell it to. To handle this, consider using the --delete flag alongside your exclude rules. However, be cautious as this will remove files from the destination that are missing from the source. Another issue is pattern precedence. If an earlier rule includes a file, a later exclude rule might not override it. Always review your rule order and test thoroughly. Additionally, verify that your shell is not interpreting the wildcard characters before passing them to rsync. Enclosing patterns in quotes, such as "*.tmp", prevents premature expansion and ensures the pattern is passed correctly to the command.

Optimizing Performance

Performance optimization goes beyond just excluding files. Using the -z flag enables compression during transfer, which can speed up network operations. Combining this with efficient exclusions creates a highly optimized sync pipeline. You can also limit the depth of recursion using --max-depth=N if you only need to sync top-level directories. This further reduces the overhead of scanning deep directory trees. For very large libraries, consider running the sync during off-peak hours to minimize impact on network availability. Regularly reviewing your exclusion list helps maintain efficiency. As new file types emerge or project structures change, update your patterns accordingly. This proactive approach ensures that your synchronization remains fast and relevant.

Frequently Asked Questions

Will rsync delete files I excluded?

No, excluding files simply prevents them from being copied to the destination. Existing files in the destination remain untouched unless you use the --delete option, which removes files from the destination that are no longer in the source.

Can I exclude files based on size?

Standard rsync does not support size-based exclusion directly. You would need to pre-filter the file list using tools like find or write a custom script to generate the exclude list based on file sizes before running rsync.

How do I exclude hidden files?

Hidden files start with a dot. You can exclude them using the pattern --exclude=".*". This will skip all files and directories beginning with a period, such as .DS_Store or .git.

What if my exclude pattern is not working?

Check if your shell is expanding the wildcard before rsync sees it. Always wrap patterns in quotes. Also, verify the order of your include and exclude rules, as earlier rules take precedence over later ones.

Is there a way to dry-run exclusions?

Yes, use the -n or --dry-run flag. This simulates the transfer without making any changes, allowing you to see exactly which files would be excluded or included based on your current settings.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More