Excluding Subfolders when Copying Files between Directories using rsync in Arch Linux

Abstract: Exclude subfolders during rsync file transfers in Arch Linux using the --exclude flag to prevent unnecessary nested content from being copied.

Created: 2026-07-27 by
To exclude subfolders when copying files between directories using rsync in Arch Linux, utilize the --exclude flag followed by the directory name. This command filters out entire subtrees while preserving the specified top-level files, ensuring efficient and targeted data synchronization without transferring unnecessary nested content.

Understanding the rsync Exclude Mechanism

The rsync utility is a powerful file transfer tool available in Arch Linux that synchronizes data between locations. By default, it copies all files and directories recursively. However, users often need to omit specific subdirectories to save bandwidth or storage space. The primary mechanism for this is the --exclude option. When you specify an exclusion pattern, rsync evaluates each file and directory against the provided rules. If a match is found, that item and all its contents are skipped during the transfer process. This is particularly useful when dealing with large project structures containing temporary files, logs, or build artifacts that do not need to be mirrored on the destination server. It is important to distinguish between excluding a single file and excluding a directory tree. Excluding a directory removes the folder itself and everything inside it from the operation. In contrast, excluding a file only skips that specific file, leaving the rest of the directory structure intact. Understanding this distinction prevents accidental data loss during synchronization tasks.

Basic Syntax for Excluding Subfolders

The fundamental command structure for excluding a subfolder involves placing the --exclude flag before the source and destination arguments. The syntax is straightforward: rsync -av --exclude 'dirname' source/ destination/. The -a flag ensures archive mode, which preserves permissions, timestamps, and symbolic links, while -v provides verbose output so you can monitor the progress. For example, if you have a source directory named project containing a subfolder named node_modules, and you want to copy everything except that subfolder, the command would look like this:
rsync -av --exclude 'node_modules' /path/to/project/ /path/to/destination/
Notice the trailing slash on the source directory /path/to/project/. This tells rsync to copy the contents of the directory rather than the directory itself. Without the trailing slash, the parent directory might be created at the destination, potentially altering your desired structure. Always verify your path syntax to ensure the correct hierarchy is maintained. You can also use wildcards within the exclude pattern. For instance, --exclude '*.log' will skip all files ending in .log, while --exclude 'temp/*' excludes everything inside a folder named temp. These patterns provide flexibility for complex filtering requirements.

Multiple Exclusions and Pattern Matching

In many scenarios, a single exclusion is insufficient. You may need to filter out multiple types of directories or files simultaneously. rsync allows you to chain multiple --exclude flags in a single command line. Each flag is evaluated independently, allowing for granular control over what gets transferred. Consider a scenario where you are syncing a web development project. You likely want to exclude both the .git directory and the vendor folder. The command would include both exclusions:
rsync -av --exclude '.git' --exclude 'vendor' /src/webapp/ /dest/webapp/
This approach keeps your command clean and readable. If you have numerous exclusions, managing them inline can become cumbersome. In such cases, consider using a filter file as described in the next section. Additionally, remember that order matters in some advanced filtering contexts, though for simple exclusions, the sequence generally does not impact the outcome. For more information on refining your transfers, you might find it helpful to review how to handle ownership and permissions during the transfer process, as detailed in How to Use rsync to Transfer Files to a Server and Set Ownership and Permissions Using sudo. This ensures that even with excluded folders, the remaining files retain their correct attributes.

Using Filter Rules for Complex Scenarios

While individual --exclude flags work well for simple cases, complex projects may require a more robust solution. rsync supports filter rules via the --filter or -f option, or by using a dedicated filter file. This method is ideal when you have dozens of exclusions or need to combine includes and excludes logically. To use a filter file, create a text file (e.g., excludes.txt) where each line contains a pattern to exclude. Then, invoke rsync with the --filter='merge /path/to/excludes.txt' option. This reads the patterns sequentially, applying them to the file list. Filter rules allow for more sophisticated logic, such as excluding a directory only if it matches certain criteria elsewhere in the path. This level of control is essential for system administrators managing large-scale deployments across multiple servers. It reduces the risk of human error associated with long command lines. If you encounter issues where permissions are not being set correctly after your transfer, refer to How to Fix Rsync Not Setting File Permissions Correctly when Transferring Local to Remote to troubleshoot common permission-related pitfalls.

Frequently Asked Questions

Does excluding a folder delete it from the destination?

No, rsync with the --exclude flag only prevents new or updated files from being copied. It does not delete existing files in the destination directory. To remove files that exist in the destination but not in the source, you must use the --delete flag carefully.

Can I exclude hidden directories using rsync?

Yes, you can exclude hidden directories just like any other folder. Use the exact name of the hidden directory, including the leading dot, in your exclude pattern. For example, --exclude '.cache' will successfully ignore the .cache directory during the transfer.

What happens if I forget the trailing slash on the source path?

Forgetting the trailing slash causes rsync to create a duplicate copy of the source directory inside the destination. Instead of merging contents, it creates a new folder with the same name as the source. Always double-check your paths to avoid unintended directory nesting.

Is there a way to dry-run exclusions before executing?

Absolutely. Adding the -n or --dry-run flag simulates the transfer without making any changes. This allows you to verify that your exclusion patterns are working as expected and that no critical files are being inadvertently skipped.

How do I exclude a directory based on a regular expression?

Standard --exclude patterns support basic shell globbing. For regular expressions, you should use the --include-from and --exclude-from options combined with a filter file, or use the --filter option with Perl-compatible regular expressions. This provides greater precision for complex naming conventions.

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