Operating System - HP-UX
1752726 Members
5924 Online
108789 Solutions
New Discussion юеВ

Re: Using "touch" command to create large files?? Is it possible??

 
Go to solution
Angie_1
Regular Advisor

Using "touch" command to create large files?? Is it possible??

Is it possible to use the touch comand to create large files? Like 50 GIG size files?

Thanks,
Angie
19 REPLIES 19
Pete Randall
Outstanding Contributor

Re: Using "touch" command to create large files?? Is it possible??

No, touch, by definition, creates a 0 byte file. Try prealloc.


Pete

Pete
Victor BERRIDGE
Honored Contributor

Re: Using "touch" command to create large files?? Is it possible??

Hi Angie,
No but you could use prealloc e.g
prealloc ./test 100000000 >> /tmp/testperf2

All the best
Victor
Angie_1
Regular Advisor

Re: Using "touch" command to create large files?? Is it possible??

I have never heard of that command "prealloc"... does this below create a 50 GIG file? Looks like a 100 meg file?

prealloc ./test 100000000 >> /tmp/testperf2

Thanks!
Angie
Fred Ruffet
Honored Contributor

Re: Using "touch" command to create large files?? Is it possible??

... or dd.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Using "touch" command to create large files?? Is it possible??

No but you could use dd to create a large (though sparse) file very quickly.

dd if=/dev/zero bs=1k seek=52428799 count=1 of=mybigfile


If you do an ls -l mybigfile, it will display 50GB but a du -k will display only only 1 block because a sparse file has "holes". When a sparse file is read, the "holes" are filled in with NUL's so a copy of mybigfile will actually use 50GB of space.
If it ain't broke, I can fix that.
Angie_1
Regular Advisor

Re: Using "touch" command to create large files?? Is it possible??

So in order to get the actual 50 GIG of space to be used up, I would have to then copy that file after creating it with dd? Let me explain what I am doing. I am purposely filling up a disk with some files to control the amount of disk space for some users. Yes I could use a quota but this is easier.

Angie
Pete Randall
Outstanding Contributor

Re: Using "touch" command to create large files?? Is it possible??

$ prealloc filler 100
$ ll filler
-rw-rw-r-- 1 plr support 100 May 18 12:20 filler
$


Pete

Pete
john korterman
Honored Contributor

Re: Using "touch" command to create large files?? Is it possible??

Hi,
if you have all that space available, you could try something like this in the directory you want the file "big" to be put:
# prealloc big $((50*1024*1024*1024*1024))

regards,
John K.
it would be nice if you always got a second chance
A. Clay Stephenson
Acclaimed Contributor

Re: Using "touch" command to create large files?? Is it possible??

No, a modified dd command will do this nicely although it will take some time. I thought you wanted something quick like touch.

dd if=/dev/zero bs=256k count=204800 of=mybigfile


and unlike prealloc, dd is a standard UNIX/Linix command
If it ain't broke, I can fix that.