Operating System - HP-UX
1837379 Members
3386 Online
110116 Solutions
New Discussion

Create a file of a specific length

 
SDS FDX
Advisor

Create a file of a specific length

What is the unix command in HP-UX to create a file of a certain length? I know that "touch" or "vi" will create a zero lenght file, but is there a way to create a file of a certain length in MB's?

Thanks
5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: Create a file of a specific length

'prealloc' will do what you need. 'man prealloc' for details.

'prealloc' works in BYTES. The basic syntax is:

# prealloc filename

So to create a file of approx. 1 MB (1,000,000 bytes):

# prealloc afile 1000000
SDS FDX
Advisor

Re: Create a file of a specific length

Thank you for your response.
Stephen Keane
Honored Contributor

Re: Create a file of a specific length

Don't forget to allocate points if someone (not me) has answered your question!
Prasad Joshi
Regular Advisor

Re: Create a file of a specific length

bash-2.02# dd if=/dev/zero of=/test bs=1024 count=1024
1024+0 records in
1024+0 records out

bash-2.02# du -k test
1024 test
Prasad Joshi
Regular Advisor

Re: Create a file of a specific length

I think dd command will also help.
This is an example which creates a file of 1MB.

bash-2.02# dd if=/dev/zero of=/test bs=1024 count=1024
1024+0 records in
1024+0 records out

bash-2.02# du -k test
1024 test


Thanks & regards,
Prasad