What command do you use to create an empty file?
In my case, I used the touch
command if the file size was 0, and the dd
command if I needed a file of a certain size, as shown below.
However, apart from the dd
command, I learned that there is a command called fallocate
as a way to create a file of a certain size, so I compared the performance of both.
[nkojima@akagi sample_files]$ touch sample.txt
[nkojima@akagi sample_files]$ dd if=/dev/zero of=./sample2.txt bs=1K count=1024
1024+0 Record input
1024+0 record output
1048576 bytes(1.0 MB)Copied, 0.00580267 seconds, 181 MB/Seconds
[nkojima@akagi sample_files]$ ls -lah
Total 1.0M
drwxrwxr-x 2 nkojima nkojima 43 June 21 12:18 .
drwx------.5 nkojima nkojima 175 June 21 12:17 ..
-rw-rw-r--1 nkojima nkojima 0 June 21 12:17 sample.txt
-rw-rw-r-- 1 nkojima nkojima 1.0M June 21 12:18 sample2.txt
dd
and fallocate
commands to create files of various sizes and measure their processing speed.dd
command is 1MB.date
command was used to measure the processing time as shown below.[root@akagi ~]# date; dd if=/dev/zero of=dd.txt bs=1M count=100; date;
Sunday, June 21, 2020 12:48:28 JST
100+0 Record input
100+0 record output
104857600 bytes(105 MB)Copied, 0.0362178 seconds, 2.9 GB/Seconds
Sunday, June 21, 2020 12:48:29 JST
[root@akagi ~]# date; fallocate -l 100m ./fallocate.txt; date;
Sunday, June 21, 2020 12:48:52 JST
Sunday, June 21, 2020 12:48:52 JST
fallocate
command was overwhelmingly faster.dd
command takes some processing time even if you use high-speed storage (NVMe-SSD), so I think that it will make a big difference if it is slow storage.file size | Processing time of dd command(Seconds) | Processing time of fallocate command(Seconds) |
---|---|---|
100MB | <1 | <1 |
500MB | <1 | <1 |
1GB | 1 | <1 |
2GB | 2 | <1 |
4GB | 4 | <1 |
8GB | 7 | <1 |
16GB | 15 | <1 |
fallocate
command instead of the dd
command.Recommended Posts