大网数据广告活动
服务器运维问答

rsync output file sizes in human-readable format

· 52CE 我爱测

when you use rsync -avzh --stats --out-format="%t %f %b" it does the output in bytes the man pages says the following In addition, one or more apostrophes may be specified prior to a numerical escape to indicate that the numerica…

问题原文

原帖链接 · Sl33py · CC BY-SA 3.0

when you use

rsync -avzh --stats --out-format="%t %f %b"

it does the output in bytes the man pages says the following

In addition, one or more apostrophes may be specified prior to a   
numerical escape to indicate that the numerical value should be made   
more human-readable. The 3 supported levels are the same as for the  
--human-readable command-line option, though the default is for human-  
readability to be off. Each added apostrophe increases the level  
(e.g. "%''l %'b %f").      

my question is how many apostrophes do I have to place between the %b to change it from bytes to mega bytes?

As soon as i add a apostrophes this is what happens in the log

rsync -av  --out-format="%t %f %'b"



2016/10/29 01:00:22 home/data/Clients/P/Power Solutions CC/2017/Sales Report %'b

I have typed the command out as not to copy html but cant seem to get the log to display correctly

社区高分解答

原帖链接 · user9517 · CC BY-SA 3.0

Reading the --human-readable section of the man page reveals

-h, --human-readable

Output numbers in a more human-readable format. This makes big numbers output using larger units, with a K, M, or G suffix. If this option was specified once, these units are K (1000), M (1000*1000), and G (1000*1000*1000); if the option is repeated, the units are powers of 1024 instead of 1000.

However that's not especially clear so let's bring Scientific Method to bear and devise an experiment. We'll use some files we have lying around and use rsync to copy them. We'll make a note of the relevant outputs it generates for each of the different command line options.

Here are the files we'll perform the experiment with.

ls -lh test.*
-rw-rw-r--. 1 iain iain     40435 Oct 31 09:08 test.png
-rw-rw-r--. 1 iain iain 853483520 Oct 31 09:08 test.tar

then we'll use rsync to copy them. Note that we delete the destination files each time but not show outr working.

Test 1

rsync -av  --out-format="%t %f %b" ./test.* /tmp/
sending incremental file list
2016/10/31 09:10:42 test.png 40482
2016/10/31 09:10:45 test.tar 853587747

so %b gives a simple bytes value

Test 2

rsync -av  --out-format="%t %f %'b" ./test.tar /tmp/
sending incremental file list
2016/10/31 09:11:25 test.png 40,482
2016/10/31 09:11:28 test.tar 853,587,747

%'b gives a bytes value separated by ,

Test 3

rsync -av  --out-format="%t %f %''b" ./test.* /tmp/
sending incremental file list
2016/10/31 09:12:29 test.png 40.48K
2016/10/31 09:12:32 test.tar 853.59M

%''b gives the KB/MB (and GB) sizes scaled appropriately

and finally

Test 4

rsync -av  --out-format="%t %f %'''b" ./test* /tmp/
sending incremental file list
2016/10/31 09:17:49 test.png 39.53K
2016/10/31 09:17:52 test.tar 814.04M

%'''b gived the values in KiB/MiB etc also scaled appropriately.

Conclusion

If you want everything expressing in MB then you can't do what you want as the output is scaled to K/M/G etc as appropriate for the file.

If you want K/M/G etc B then '' and if you want KiB/MiB/GiB etc then ''' is what you want.

So, the answer to your question is, it depends on what you mean by

change it from bytes to mega bytes

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。