8

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

1 Answer 1

17

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

2
  • Thank you your answer explains very clearly what the different levels are. If i use the code in the log file as soon as i move from %b to %'b i dont get the numbers anymore but %'b I have typed it out so not to copy the html I will edit my question to make my question more clear as it is in fact 2 questions
    – Sl33py
    Nov 1, 2016 at 15:40
  • 3
    the command ls -lh is wrong, this is the output of ls -l
    – pim
    Oct 31, 2017 at 5:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .