我的操作系统和驱动器是

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

那么,如何在secs中创建超大文件

我被告知使用MappingFile函数。我无法通过2G创建文件 所以... 您的热烈回应将受到赞赏 感谢

有帮助吗?

解决方案

在Linux中使用 dd 创建一个1 GB的文件需要57秒的“挂钟时间”,在一个有点装载的盒子上,磁盘速度慢,系统时间约为17秒:

$ 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
$

其他提示

你可以使用dd

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

或只是普通的shell脚本和内容无关紧要

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

再做一次

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

文件是否必须占用实际磁盘空间?如果没有,你可以随时(在Cygwin或Linux中):

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

这将在几分之一秒内创建一个空的7 TB文件。当然,它不会分配太多的实际磁盘空间:你将有一个很大的稀疏文件

在Cygwin或Linux下编写程序,你可以在C程序中做同样的事情,调用 ftruncate

根据您的系统限制,您可以在几分之一秒内创建一个大文件......

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

玩这个。

cat / dev / urandom&gt;&gt; /家庭/ mybigfile

当磁盘空间用完时会出错。

这是针对linux / bsd /可能是cgywin

在虚拟机中,我做了 dd if = / dev / zero of = file; rm file ,它填满了磁盘,当它完全删除了文件。这让我可以出于某种原因压缩图像,我读到了在某个论坛上做这件事。

您可以使用“fsutil”命令为Win2000 / XP / 7:

C:GT; fsutil 文件createnew 用法:fsutil文件createnew    例如:fsutil文件createnew C:\ testfile.txt 1000

Reagrds

如果你想要一个稀疏文件,你也可以在Windows上(在NTFS卷上),使用CreateFile,DeviceIOFunction和FSCTL_SET_SPARSE以及FSCTL_SET_ZERO_DATA进行;有关详细信息,请参阅此处

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top