How to create a super-huge file with pure c or linux-shell or dos commands?

My os and drive

OS: Windows XP sp2 or Linux SUSE 9 or Cygwin
Compiler: Visual C++ 2003 or Gcc or Cygwin
PC and os are both 32 bits

So how can I create a super-huge file in secs

I was told to use the MappingFile functions. I was not able to create files through 2G So ... Your warm feedback will be appreciated thanks

+3
source share
8 answers

Using ddLinux to create a 1 GB file takes 57 seconds a "wall clock" on a slightly loaded box with a slow disk and about 17 seconds of system time:

$ time dd if=/dev/zero of=bigfile bs=G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 53.9903 s, 19.9 MB/s

real    0m56.685s
user    0m0.008s
sys     0m17.113s
$
+10
source

you can use dd

dd if=/dev/zero of=bigfile.txt bs=$((1024*1024)) count=100

or just a simple script and the content doesn't matter

1) create a dummy file with a few lines, eg 10 lines
2) use cat dummy >> bigfile in a while loop

eg

    while true
    do
      cat dummy >> bigfile.txt 
      #check for number of lines more than 10000 for example and break out of loop
    done

Do it again

while true
do
  cat bigfile >> bigfile2.txt           
  # check for size and break out..
done
rm -f dummy bigfile
+4

? , ( Cygwin Linux):

dd if=/dev/zero of=bigfile seek=7T bs=1 count=1

7 . , : .

Cygwin Linux, C ftruncate.

+2

...

FILE *fp = fopen("largefile" ,"w");
for(int i = 0; i < 102400; i++)
{
    fseek(fp, 10240000, SEEK_CUR);
}
fprintf(fp, "%c", 'x');
fclose(fp);

.

+2

cat/dev/urandom → /home/mybigfile

, .

linux/bsd/ cgywin

+2

suse VM dd if=/dev/zero of=file;rm file, , , . - , , -.

+1

"fsutil" Win2000/XP/7:

c: > fsutil createnew : fsutil  : fsutil C:\testfile.txt 1000

Reagrds

+1

, Windows ( NTFS), CreateFile, DeviceIOFunction FSCTL_SET_SPARSE FSCTL_SET_ZERO_DATA; . .

0

Source: https://habr.com/ru/post/1724256/


All Articles