rsync 人类可读格式的输出文件大小

Sl3*_*3py 3 linux rsync

当你使用

rsync -avzh --stats --out-format="%t %f %b"
Run Code Online (Sandbox Code Playgroud)

它以字节为单位输出手册页说以下内容

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").      
Run Code Online (Sandbox Code Playgroud)

我的问题是我必须在 %b 之间放置多少个撇号才能将其从字节更改为兆字节?

一旦我添加撇号,这就是日志中发生的事情

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



2016/10/29 01:00:22 home/data/Clients/P/Power Solutions CC/2017/Sales Report %'b
Run Code Online (Sandbox Code Playgroud)

我已经输入了不复制 html 的命令,但似乎无法正确显示日志

use*_*517 9

阅读--human-readable手册页的部分揭示了

-h,--人类可读的

以更易于阅读的格式输出数字。这使得使用更大单位的大数字输出,带有 K、M 或 G 后缀。如果此选项指定一次,则这些单位为 K (1000)、M (1000*1000) 和 G (1000*1000*1000);如果重复该选项,则单位是 1024 的幂而不是 1000。

然而,这不是特别清楚,所以让我们用科学方法来承担并设计一个实验。我们将使用我们现有的一些文件并使用 rsync 复制它们。我们将记下它为每个不同的命令行选项生成的相关输出。

以下是我们将用于执行实验的文件。

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
Run Code Online (Sandbox Code Playgroud)

然后我们将使用 rsync 来复制它们。请注意,我们每次都删除目标文件,但不显示 outr 工作。

测试 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
Run Code Online (Sandbox Code Playgroud)

所以%b给出了一个简单的字节值

测试 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
Run Code Online (Sandbox Code Playgroud)

%'b 给出一个由分隔的字节值 ,

测试 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
Run Code Online (Sandbox Code Playgroud)

%''b 给出适当缩放的 KB/MB(和 GB)大小

最后

测试 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
Run Code Online (Sandbox Code Playgroud)

%'''b 鉴于 KiB/MiB 等中的值也进行了适当的缩放。

结论

如果您希望所有内容都以 MB 表示,那么您将无法执行所需的操作,因为输出会根据文件缩放为 K/M/G 等。

如果您想要 K/M/G 等 B,那么''如果您想要 KiB/MiB/GiB 等,那么'''这就是您想要的。

所以,你的问题的答案是,这取决于你的意思

将其从字节更改为兆字节

  • 命令 `ls -lh` 是错误的,这是 `ls -l` 的输出 (3认同)