Under non-embedded Linux or Cygwin (or any system with GNU coreutils) and FreeBSD:
truncate -s 24m example.file
This creates a file full of null bytes. If the file already exists and is smaller, it is extended to the requested size with null bytes. If the file already exists and is larger, is is truncated to the requested size.
The null bytes do not consume any disk space, the file is a sparse file.
On many systems, head -c 24m </dev/zero >example.file
creates a non-sparse file full of null bytes. If head
doesn't have a -c
option on your system (it's common but not in POSIX), you can use dd bs=1024k count=24 </dev/zero >example.file
instead (this is POSIX-compliant).