Excluding Subfolders while Copying Files and Directories using rsync in Arch Linux
In this article, we will discuss how to use the rsync command in Arch Linux to copy files and directories from one directory to another, while excluding subfolders. This can be useful in many scenarios, such as when you want to make a copy of a directory, but don't want to include certain subfolders in the copy.
What is rsync?
rsync is a powerful command-line tool that is used for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. It efficiently copies and syncs only the changed blocks and bytes to the destination instead of copying the entire file which makes it faster than other copying tools.
Excluding Subfolders while Copying
To exclude subfolders while copying files and directories using rsync, you can use the --exclude option followed by the name of the subfolder you want to exclude. For example, if you want to copy the contents of the directory test2 to the directory Destination, but want to exclude the subfolder test2/subfolder1, you can use the following command:
rsync -av --exclude='subfolder1' test2/ Destination/
In the above command, the -a option is used to preserve the file attributes such as ownership, permissions, and timestamps. The -v option is used to enable verbose output, which displays the files being copied. The --exclude option is used to exclude the subfolder subfolder1 from the copy process.
Excluding Multiple Subfolders
If you want to exclude multiple subfolders, you can use multiple --exclude options. For example, if you want to exclude both subfolder1 and subfolder2, you can use the following command:
rsync -av --exclude='subfolder1' --exclude='subfolder2' test2/ Destination/
Excluding a Pattern of Subfolders
If you want to exclude all subfolders that match a certain pattern, you can use the --exclude-from option followed by a file that contains the list of patterns to exclude. For example, if you want to exclude all subfolders that start with the name sub, you can create a file called exclude.txt with the following contents:
sub*
And then use the following command to exclude all subfolders that match the pattern:
rsync -av --exclude-from='exclude.txt' test2/ Destination/
rsync is a powerful command-line tool that can be used to copy and synchronize files and directories in Linux/Unix systems. By using the --exclude option, you can exclude subfolders from the copy process. This can be useful in many scenarios, such as when you want to make a copy of a directory, but don't want to include certain subfolders in the copy.
References
- rsync man page
- 15 rsync commands for local and remote file synchronization
- How to use rsync exclude file to exclude files and directories
This article covers the following types of references:
- Online resources