日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

20+ Rsync command’s switches and common usages with examples – Unix/Linux--reference

發(fā)布時間:2025/4/5 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 20+ Rsync command’s switches and common usages with examples – Unix/Linux--reference 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

reference:http://crybit.com/rsync-commands-switches/

The “rsync” is a powerful command under the Linux environment. The rsync stands for Remote Sync. Normally rsync is used to transfer file from one server(source) to another server(destination). rsync has a lot of switches or option for managing the command much usefully. Here I am explaining the switches of rsync command with examples. Rsync will actually look and see what in the file has changed and upload only the part of the file that has changed. Unlike ftp and other transfer solutions rsync doesn’t simply re-upload the entire file.

Common Syntax for Rsync:

# rsync [options] Source Destinations.

Switches of rsync:

1, -v, –verbose
Increase verbosity.

Example:
I’ve created a file ‘rsync’ under ‘/root/Rsync/’ for testing purpose.

root@server [~]# rsync -v /root/Rsync/rsync . rsyncsent 65 bytes received 31 bytes 192.00 bytes/sec total size is 0 speedup is 0.00

2, -r, –recursive
Recurse into directories.

3, -l, –links
Copy symlinks as symlinks.

4, -p, –perms
Preserve permissions.

5, -t, –times
Preserve modification times.

6, -g, –group
Preserve group.

7, -o, –owner
preserve owner (super-user only)

8, -D
Same as –devices –specials.
–devices :?preserve device files (super-user only).
–specials :?preserve special files.

9, -H, –hard-links
Preserve hard links

10, -A, –acls
Preserve ACLs (implies –perms)

11, -X, –xattrs
Preserve extended attributes

12, -a, –archive
This is very important rsync switch, because it can be done the functions of some other switches combinations.
Archive mode; equals -rlptgoD (no -H,-A,-X)

13, -q, –quiet
Suppress non-error messages.

14, To specify the file size for sync:
–max-size=SIZE
Don’t transfer any file larger than SIZE
–min-size=SIZE
Don’t transfer any file smaller than SIZE

15, –delete
Delete extraneous files from destination dirs.

16, W, –whole-file
Copy files whole (without delta-xfer algorithm)

17, -u, –update
Skip files that are newer on the receiver. Means, Do Not Overwrite the Modified Files at the Destination.

18, –progress
View the rsync Progress during Transfer.

19, Include and Exclude Pattern.
–include
–exclude
Patterns are expressed in single quote.

Examples:

[root@ser crybit]# rsync -avz --include 'c*' --exclude '*' /root/crybit/ 109.200.11.67:/root/Rsinc101 root@109.200.11.67's password: stdin: is not a tty sending incremental file list cry1.doc cry2.doc cry3.doc cry4.doc cry5.docsent 267 bytes received 107 bytes 68.00 bytes/sec total size is 0 speedup is 0.00

In the above example files starting with ‘c’ are included for Rsync and all other files are excluded on Rsync operation.

20 -e : Rsync over Shell(SSH)
Syntax:

# rsync -avz -e ssh Source Destination

Some useful switches combinations and Useful “Rsync” examples:

1, How to Sync two directories in the same machine ?
I have created two directories(also some files inside each dir) under /root location to check the rsync usages.

/root/Rsync1/ /root/Rsync2/

Example:

root@server [~]# rsync -zvr /root/Rsync1/ /root/Rsync2/ sending incremental file list rsync1.txt rsync10.txt rsync2.txt rsync3.txt ...... ...... sent 502 bytes received 202 bytes 1408.00 bytes/sec total size is 0 speedup is 0.00

Where,
-z?is to enable compression
-v?verbose
-r?indicates recursive

2, Preserve the following option while Sync files using -a switch.

r, l, p, t, g, o, D : Switch details are mentioned in the above section. Recursive mode, symbolic links, permissions, timestamp, owner and group

See the example below:

root@server [~]# ll /root/Rsync1/rsync10.txt -rw-r--r-- 1 root root 0 Feb 17 07:40 /root/Rsync1/rsync10.txt root@server [~]# ll /root/Rsync2/rsync10.txt -rw-r--r-- 1 root root 0 Feb 17 07:40 /root/Rsync2/rsync10.txt

3, How to Rsync files from remote server to local ?
It is quit similar to SCP, the syntax for doing the same is pasted below:

# rsync -azv Remote-IP:/path/for/Sync /Path/to/Sync

Some examples:
Sync the directory from remote to local

[root@ser crybit]# rsync -azv MY.SERVER.IP:/root/Rsync1 /root/crybit/ root@109.200.11.67's password: stdin: is not a tty receiving incremental file list Rsync1/ Rsync1/rsync1.txt Rsync1/rsync10.txt Rsync1/rsync2.txt Rsync1/rsync3.txt ..... ..... sent 205 bytes received 527 bytes 77.05 bytes/sec total size is 0 speedup is 0.00

Sync all files from remote to local

[root@ser crybit]# rsync -azv 109.200.11.67:/root/Rsync1/* /root/crybit/ root@109.200.11.67's password: stdin: is not a tty receiving incremental file list rsync1.txt rsync10.txt rsync2.txt rsync3.txt ... ... sent 201 bytes received 499 bytes 93.33 bytes/sec total size is 0 speedup is 0.00

4, How to sync files from local to remote server ?
Syntax:

# rsync -azv /local-path/for/Sync/ Remote-IP:/path/to/Sync

Examples:

[root@support crybit]# rsync -avz /root/crybit/ 109.200.11.67:/root/Rsinc101 root@109.200.11.67's password: stdin: is not a tty sending incremental file list created directory /root/Rsinc101 ./ rsync1.txt rsync10.txt rsync2.txt rsync3.txt ... ... sent 1028 bytes received 399 bytes 190.27 bytes/sec total size is 0 speedup is 0.00 Note 1 : In example 3 and 4 you can use user@IP:/path format, if you have only the user privilege on server Note 2 : The rsync will automatically create the destination directory/location if it isn't there.

That’s it !!?

Related:
groupdel,?groupmems,?groupmod,?useradd?,?usermod?,?chgrp,?chown,?ls,?head,?tail,?top,?ps,?find,crontab,?ftp commands,?tar,?rpm,

轉載于:https://www.cnblogs.com/davidwang456/p/3602554.html

總結

以上是生活随笔為你收集整理的20+ Rsync command’s switches and common usages with examples – Unix/Linux--reference的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。