-3

I want to create the file to implement a I/O benchmark on linux.

Thanks in advance, Antonio

rubik90
  • 67
  • 10
  • 3
    See this answer over at the Unix StackExchange: https://unix.stackexchange.com/questions/101332/generate-file-of-a-certain-size – Blaze Oct 05 '18 at 14:30
  • There is the link shared above by @Blaze with the solution you want. In addition there are several other links solving this same problem. With a quick search for Satckoverflow you will find several answers. – Geraldo Novais Oct 05 '18 at 17:03
  • Another link inside Stackoverflow that solves the same thing: https://stackoverflow.com/questions/139261/how-to-create-a-file-with-a-given-size-in-linux – Geraldo Novais Oct 05 '18 at 17:14

2 Answers2

0

If you are using a filesystem which supports it, you can do this with fallocate. Here is the command line version

/tmp/tmp.tO6EDnuWXT λ > fallocate -l 10MiB derp
/tmp/tmp.tO6EDnuWXT λ > du derp
10240   derp

There is also a C API for this. http://man7.org/linux/man-pages/man2/fallocate.2.html

isomarcte
  • 1,981
  • 12
  • 16
0

If the contents of the file do not matter, you can do something like:

dd if=/dev/random of=./derp bs=1024 count=10000

bs is the block size, so in the above example I am creating the file in 1024 (1K) chunks, and count is how often I do this (1K * 10000 = 10M). See https://www.linuxnix.com/what-you-should-know-about-linux-dd-command/ for more examples

thurizas
  • 2,473
  • 1
  • 14
  • 15