First, let’s clean the contents of source_directory, and then create a FIFO file in source_directory using the mkfifo command: $ rm –rf source_directory/* Now, we’ll try to copy a FIFO file using rsync. We were successful in copying the device file this time. $ rsync –D /dev/null destination_directory/Ĭrw-r-r- 1 root root 1, 3 Aug 12 18:02 null Let’s try to copy it using the -D option: $ rm –rf destination_directory We didn’t use any of the options of rsync, and we couldn’t copy the device file /dev/null. Let’s copy /dev/null, which is a device file, to destination_directory: $ rm –rf destination_directory The –specials option is necessary for copying files such as FIFO files and named sockets.įirst, we’ll try to copy a device file using rsync. We must have root privileges for copying device files. The –devices option is for copying device files. Now, both the owner and group of the source file were preserved. rw-r-r- 1 bob staff 0 Aug 12 21:49 destination_directory/file1 $ rsync –go source_directory/file1 destination_directory/ If we want to keep the group of the original file in source_directory, we can use the -g option as we saw before: $ rm –f destination_directory/file1 This time, we were able to keep the owner of the file. rw-r-r- 1 bob root 0 Aug 12 21:48 destination_directory/file1 So, let’s copy the file once more with root privileges: $ rm –f destination_directory/file1 We still couldn’t keep the owner of the file as the user alice copied the file. rw-r-r- 1 alice alice 0 Aug 12 21:47 destination_directory/file1 $ rsync –o source_directory/file1 destination_directory/ Now, let’s have the user alice copy file1 in source_directory using the -o option of rsync: $ rm –f destination_directory/file1 We couldn’t preserve the owner of the source file, which is bob. The owner of the copied file in destination_directory is the user alice. rw-r-r- 1 alice alice 0 Aug 12 21:46 destination_directory/file1 Let’s have the user alice try to copy it to destination_directory using rsync: $ rsync source_directory/file1 destination_directory/ We’ll use the following directory for examining the -o option: $ ls –l source_directory/ Now, destination_directory/file1 has the same group as source_directory/file1 thanks to the -g option of rsync. rw-r-r- 1 alice staff 0 Aug 12 20:11 destination_directory/file1 What if we want to preserve the group of the file in source_directory? Then, we must use the -g option: $ rsync –g source_directory/file1 destination_directory/ Since the group alice is the primary group for the user alice, the file file1 in destination_directory had the group alice. We didn’t use any options while using rsync. rw-r-r- 1 alice alice 0 Aug 12 20:10 destination_directory/file1 Let’s copy the file file1 in source_directory to destination_directory using rsync: $ rsync source_directory/file1 destination_directory/ staff is a secondary group for the user alice. The primary group for the user alice is alice. On the other hand, file1 in destination_directory has the group alice. file1 in source_directory has the group staff. The files have the same owner but different groups. We have the file file1 in both directories. We’ll use the following directory for examining the -g option: $ ls –l source_directory/ In order to keep the modification time of the file from the source directory, we must use the -t option of rsync: We recorded this time using the date command while copying the file. In fact, it’s the creation time of the file in destination_directory. rw-r-r- 1 alice alice 0 Aug 12 20:05 destination_directory/file1Īs we see, the modification time of file1 in destination_directory is different from the modification time of file1 in source_directory. Let’s check the modification time of file1 in destination_directory: $ ls –l destination_directory/file1 $ date rsync source_directory/file1 destination_directory/ Now, let’s copy this file to destination_directory without using any options: $ rm –f destination_directory/file1 The modification time of file1 in source_directory is Aug 12 20:00. rw-r-r- 1 alice alice 0 Aug 12 20:00 source_directory/file1 Let’s verify this using the following file: $ ls –l source_directory/file1 If we copy files using rsync without any options, rsync doesn’t preserve the modification times of the files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |