Operating System - HP-UX
1828843 Members
2661 Online
109985 Solutions
New Discussion

Re: command to create file with certain size

 
SOLVED
Go to solution
Frank de Vries
Respected Contributor

command to create file with certain size

I forgot which command (not touch) you can create a file with a certain size
Look before you leap
5 REPLIES 5
Elmar P. Kolkman
Honored Contributor

Re: command to create file with certain size

dd is your friend:
dd of= bs=1024 count= if=/dev/zero
Every problem has at least one solution. Only some solutions are harder to find.
Frank de Vries
Respected Contributor

Re: command to create file with certain size

dd may do the trick, however I was looking for a different command.
Look before you leap
Robert-Jan Goossens
Honored Contributor
Solution

Re: command to create file with certain size

Hi,

You can create a file with prealloc,

# prealloc file 10000000 ( 10 mb)

Hope it helps,

Robert-Jan.
Frank de Vries
Respected Contributor

Re: command to create file with certain size

That's then one, full marks !
Look before you leap
Elmar P. Kolkman
Honored Contributor

Re: command to create file with certain size

You can do it different too, but to create a sparse file. In C it will look like below. Of course things like parameter checking etc. are necessary if you really want to use this...
--- ---
#include
#include

void main(int argc,char **argv)
{
int fd=open(argv[1],O_WRONLY|O_CREAT);
lseek(fd,atoi(argv[2]),SEEK_SET);
close(fd);
}
Every problem has at least one solution. Only some solutions are harder to find.