Linux中的单位换算小实验
1M=1024K/k
1G=1024M
K/k 大小写均可用
M/G只能大写
测试案例使用dd来验证
dd --help
N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =10001000, M =10241024, xM =M
GB =100010001000, G =102410241024, and so on for T, P, E, Z, Y.
[root@wql ~]# dd if=/dev/zero of=1024M bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 5.78752 s, 186 MB/s
[root@wql ~]# dd if=/dev/zero of=1000M bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 2.93391 s, 357 MB/s
[root@wql ~]#
[root@wql ~]#
[root@wql ~]# dd if=/dev/zero of=1G bs=1G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 1.58602 s, 677 MB/s
[root@wql ~]#
[root@wql ~]#
[root@wql ~]# ll
total 3123200
-rw-r--r-- 1 root root 1048576000 Apr 7 23:54 1000M
-rw-r--r-- 1 root root 1048576 Apr 7 23:53 1024k
-rw-r--r-- 1 root root 1073741824 Apr 7 23:54 1024M
-rw-r--r-- 1 root root 1073741824 Apr 7 23:54 1G
-rw-r--r-- 1 root root 1048576 Apr 7 23:53 1M
-rw-r--r-- 1 root root 0 Apr 7 23:08 1.txt
-rw-r--r-- 1 root root 0 Apr 7 23:08 2.txt
-rw-r--r-- 1 root root 0 Apr 7 23:08 3.txt
[root@wql ~]#
案例 K和k均可作为单位使用
[root@wql ~]# dd if=/dev/zero of=test bs=1k count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.00389839 s, 269 MB/s
[root@wql ~]# ll test
-rw-r--r-- 1 root root 1048576 Apr 7 23:58 test
[root@wql ~]#
[root@wql ~]# dd if=/dev/zero of=test bs=1K count=1024
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.00309509 s, 339 MB/s
[root@wql ~]# ll test
-rw-r--r-- 1 root root 1048576 Apr 7 23:58 test
[root@wql ~]# ll -h test
-rw-r--r-- 1 root root 1.0M Apr 7 23:58 test
[root@wql ~]#
案例 M和G只能使用大写
[root@wql ~]# dd if=/dev/zero of=test bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0267725 s, 392 MB/s
[root@wql ~]# dd if=/dev/zero of=test bs=1m count=10
dd: invalid number ‘1m’
[root@wql ~]#
[root@wql ~]# dd if=/dev/zero of=test bs=1G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 1.24368 s, 863 MB/s
[root@wql ~]# dd if=/dev/zero of=test bs=1g count=1
dd: invalid number ‘1g’
[root@wql ~]#