[20170925]建立文件分配大小.txt

[20170925]建立文件分配大小.txt

--//有时候工作需要建立一个文件.一般在linux下使用dd.总结一下其他方法:

1.方法1:

$ cat a.c

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/io.h>
#include <stdio.h>
int main()
{
    FILE* file = fopen ("test", "w+");
    fseek (file, 64, SEEK_SET);
    fprintf (file, "x");
    fclose (file);
    return 0;
}

$ gcc a.c
$ ./a.out

$ xxd -c 16 test
0000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000040: 78                                       x

--//偏移从0记数,这样建立的文件大小是65字节.

2.方法2:.fallocate

--//实际上linux下有一个命令建立与分配文件大小.fallocate命令.我仅仅知道centos6.X版本有这个命令.
--//按照man文档的提示:内核版本是2.6.31.

# man fallocate

FALLOCATE(1)                                                      FALLOCATE(1)

NAME
       fallocate - preallocate space to a file.

SYNOPSIS
       fallocate [-n] [-o offset] -l length filename

DESCRIPTION
       fallocate  is  used to preallocate blocks to a file.  For filesystems which support the fallocate system call,
       this is done quickly by allocating blocks and marking them as uninitialized, requiring no IO to the data blocks.
       This is much faster than creating a file by filling it with zeros.

       As of the Linux Kernel v2.6.31, the fallocate system call is supported by the btrfs, ext4, ocfs2, and xfs
       filesystems.

       The exit code returned by fallocate is 0 on success and 1 on failure.

#  fallocate -l 10 a
#  ls -l a
-rw-r--r-- 1 root root 10 2017-09-25 15:23:28 a

3.windows下:

--//windows下:
R:\>fsutil file createnew test.out 64
已创建文件 R:\test.out

R:\>dir test.out
 驱动器 R 中的卷是 RAMDISK
 卷的序列号是 0122-14E0

 R:\ 的目录

2017/09/25  15:21                64 test.out
               1 个文件             64 字节
               0 个目录    652,371,968 可用字节

R:\>d:\tools\Vim\vim74\xxd.exe -c 16 test.out
0000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000  ................

时间: 2024-09-12 16:05:25

[20170925]建立文件分配大小.txt的相关文章

[20130402]分区的段大小.txt

[20130402]分区的段大小.txt 参看链接:http://hemantoracledba.blogspot.com/2013/03/segment-size-of-partition-11202-and.html 自己重复它的测试,仅仅使用表空间名字与他不同吧了. SQL> @ver BANNER -------------------------------------------------------------------------------- Oracle Database

[20151024]关于ctas与建立主键.txt

[20151024]关于ctas与建立主键.txt --前一阵子别人问的问题,就是ctas是否可以建立主键,对于这种情况平时不这么建立,我给看看文档. --平时我建立测试表 create table t as select rownum id ,'test' name from dual connect by level<=10; --要实现ctas同时建立主键,看看如下是否可行: SCOTT@test01p> @ver1 PORT_STRING                    VERS

[20160911]windows下建立硬链接.txt

[20160911]windows下建立硬链接.txt --大家知道linux ln命令可以建立硬连接或者软连接.参考: http://blog.itpub.net/267265/viewspace-1812272/ --实际上windows下也有类似ln命令,只不过许多人很少在命令行使用windows,对于里面的命令行命令知道的更少. --通过例子说明,使用fsutil就可以建立硬连接.补充一点建立这种硬连接仅仅支持NTFS文件系统,不要指望支持FAT32. --实际上这个测试,主要有用户需求

[20160921]linux下建立samba服务器.txt

[20160921]linux下建立samba服务器.txt --工作需要,需要在linux下配置samba服务.好久不做这些事情,做一个安装笔记: 1.安装samba软件包 # rpm -qa | grep samba samba-client-3.0.33-3.39.el5_8 samba-common-3.0.33-3.39.el5_8 samba-3.0.33-3.39.el5_8 --注意安装samba-3.0.33-3.39.el5_8需要 perl-Convert-ASN1-0.2

[20141217]记录长度与块大小.txt

[20141217]记录长度与块大小.txt --昨天看了http://savvinov.com/2014/12/15/4k-bug-is-not-a-bug/ --提到转载: A couple of weeks back I received an update on my "4k bug" SR (slow multirow DML performance for small block sizes). As it turns out, the observed behavior

[20150930]linux ln建立硬连接.txt

[20150930]linux ln建立硬连接.txt --前几天同事在建立测试环境时磁盘空间不足,而另外一个空间磁盘空间充足,我说可以通过ln建立软连接来解决这个问题. --这让我想起我以前管理数据库通过ln建立硬连接来避免oracle数据文件的删除,虽然现在我现在不用这种方式,不过还是做一些简单介 --绍. 1.关于linux的ln命令我不做介绍,自己看看手册. --仅仅说明一点,做硬链接不能跨文件系统. 2.实际上很简单,我拿测试环境做一次. RMAN> report schema; us

[20151124]快速建立测试数据库.txt

[20151124]快速建立测试数据库.txt -- 以建立11.2.0.4的数据库为例子说明,以前写过使用内存来运行测试数据库,以这个为基础并且做一个记录. -- 重新删除在建立数据库. startup nomount; alter system enable restricted session; RMAN> drop database including backups; 1.建立内存盘: # mkdir -p /mnt/ramdisk # mount -t tmpfs -o size=8

[20140529]建立视图问题.txt

[20140529]建立视图问题.txt --昨天想将在10g下建立的视图移植到11g,遇到一个奇怪的问题,自己做一个记录. orcl> @ver BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi orcl> create table t  ( id number,c1 v

[20130527]估计redo文件的大小.txt

[20130527]估计redo文件的大小.txt     oracle一般建议20-30分钟切换一次redo文件.简单的查询计算如下: 参考链接:http://www.gokhanatil.com/2009/08/optimum-size-of-the-online-redo-log-files.html         SELECT(SELECT ROUND(AVG(BYTES) / 1024 / 1024, 2) FROM V$LOG) AS "Redo size (MB)",R