How To Exclude Specific Directories From Copying In Linux
As you may already know, Rsync is a fast and versatile tool to copy files and folders locally, or to/from another host over any remote shell, or to/from a remote rsync daemon. Rsync has lot useful options. One of the useful option is –exclude. Using exclude option, we can exclude certain files/directories from copying. Let us see how to do it with an example.
Let us say you have a folder called ostechnix. Inside the directory ostechnix, there are three sub-directories namely dir1, dir2, and dir3.
Sample output:
You want to copy dir1 and dir3 to different location, but not dir2. How? Here is where rsync comes in help.
To exclude a specific directory from copying using rsync command, just run:
Sample output would be:
The above command will copy all contents of the folder ostechnix to a folder namely backup, and it will exclude the directory dir2 from copying.
Alternatively, you can use the same command as below.
Example:
It is actually a good idea to omit or exclude some big or less important directories from copying while backup your system using rsync in order to save your time.
No comments:
Post a Comment