There are several solutions.
dd like solution may take some time, however using seek
dd of=mybigfile bs=1 count=0 seek=40G
is instant. however the 40g space taken by the command is not seen in
So the best is probably
fallocate -l 40g mybigfile
that creates instantly mybigfile and the space is actually reserved from the FS (and is seen in
-- edit after comment --
What about a hard link
make 40g file "myfile"
then for each test
ln ../data/myfile testfile
command to unlink testfile
data and test dirs being on the same FS (different dirs to prevent mistakes etc..).
The hard link status is pretty transparent and is not likely to be tested by the application . The unlink operation will remove the name associated with the inode and then decrement the links counter in the inode, and should be very fast (the file and its data will be actually freed only when the inode counter goes down to zero - which will not happen unless you unlink also