LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1111|回复: 3

怎么创建一个1MB的文件?

[复制链接]
发表于 2004-1-21 11:49:59 | 显示全部楼层 |阅读模式
在Linux 系统中创建一个较大容
量的文件,作为所设计的文件系统的“文件卷”.这个文件的大小为1MB
请问怎么实现。
发表于 2004-1-21 12:52:56 | 显示全部楼层
那就创建一个具有空洞的文件。


  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. int
  6. main(void)
  7. {
  8.      int fd;
  9.      if((fd=creat("file.hello",
  10.               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))<0) {
  11.                 printf("create error\n");
  12.                 exit(-1);
  13.      }
  14.      if(lseek(fd,1048576,SEEK_SET)==-1) {
  15.                 printf("lseek error\n");
  16.                 exit(-1);
  17.      }
  18.      exit(0);
  19. }
复制代码
发表于 2004-2-12 00:26:43 | 显示全部楼层
楼主是不是华工的?
发表于 2004-2-12 20:40:30 | 显示全部楼层
也可以用dd创建一个零文件。
dd if=/dev/zero of=outfile bs=1024 count=1024
这样,outfile就是一个1M的零文件。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表