The first time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination. It’s faster than scp ( Secure Copy) because rsync uses a remote-update protocol which allows transferring just the differences between two sets of files.Supports copying links, devices, owners, groups, and permissions.It efficiently copies and sync files to or from a remote system.Some Advantages and Features of Rsync Command You don’t need to be a root user to run the rsync command. This article explains 10 basic and advanced usage of the rsync command to transfer your files remotely and locally in Linux-based machines. Rsync Local and Remote File Synchronization With the help of the rsync command, you can copy and synchronize your data remotely and locally across directories, disks, and networks, perform data backups, and mirror between two Linux machines. In this tutorial, you learned how to exclude files and directories when transferring data with Rsync.Rsync ( Remote Sync) is the most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/ Unix systems. -files-from=- means include only the files from the standard input (files passed from the find command).will remove the src_directory/ from the file path. | rsync -a -files-from=- src_directory/ dst_directory/ To rsync: find src_directory/ -name "*.jpg" -printf %P\\0 Without this rsync will only copy *.jpg files in the top level directory.Īnother option would be to pipe the output of the find command -include='*/' - Then we are including all directories inside the in src_directory directory.-include='*.jpg' - First we are including all.When using multiple include/exclude option, the first matching rule applies. One option is to use the following command: rsync -a -m -include='*.jpg' -include='*/' -exclude='*' src_directory/ dst_directory/ Let’s say you want to exclude all other files and directories except the files ending with. It is little trickier to exclude all other files and directories except those that match a certain pattern. jpg files you would run: rsync -a -exclude '*.jpg*' src_directory/ dst_directory/ With rsync you can also exclude files and directories based on a pattern that matches the file or directory name.įor example, to exclude all. The command below does exactly the same as the one above: rsync -a -exclude-from='exclude-file.txt' src_directory/ dst_directory/Įxclude Multiple Files or Directories Based on a Pattern # If the number of the files and/or directories you want to exclude is large, instead of using multiple -exclude options you can specify the files and directories you want to exclude in a file and pass the file to the -exclude-from option. If you prefer to use a single -exclude option you can list the files and directories you want to exclude in curly braces src_directory/ dst_directory/ To exclude multiple files or directories simply specify multiple -exclude options: rsync -a -exclude 'file1.txt' -exclude 'dir1/*' -exclude 'dir2' src_directory/ dst_directory/ If you want to exclude the directory content but not the directory itself use dir1/* instead of dir1: rsync -a -exclude 'dir1/*' src_directory/ dst_directory/ Exclude Multiple Files or Directories # In the following example the file src_directory/file.txt will not be transferred: rsync -a -exclude 'file.txt' src_directory/ dst_directory/ Exclude a Specific Directory #Įxcluding a specific directory is same as excluding a file, just pass the relative path to the directory to the -exclude option as shown below: rsync -a -exclude 'dir1' src_directory/ dst_directory/ To exclude a specific file, pass the relative path to the file to the -exclude option.
0 Comments
Leave a Reply. |