文章目录
在很多场景下我们需要一个很大的文件,例如测试网速,测试硬盘配额大小等等。如果这时候电脑上没有单个的大文件就会比较尴尬。如果你用的是windows环境,fsutil
命令可以帮你解决这个烦恼。这一节我们一起来看看这个命令。
我是T型人小付,一位坚持终身学习的互联网从业者。喜欢我的博客欢迎在csdn上关注我,如果有问题欢迎在底下的评论区交流,谢谢。
简单介绍
根据官方介绍,fsutil
命令用来进行FAT和NTFS文件系统的相关操作。
Performs tasks that are related to file allocation table (FAT) and NTFS file systems, such as managing reparse points, managing sparse files, or dismounting a volume.
使用方法详解
首先用管理员身份打开命令提示符,直接输入fsutil
查看其参数,如下
C:\Windows\system32>fsutil
---- Commands Supported ----
8dot3name 8dot3name management
behavior Control file system behavior
dax Dax volume management
dirty Manage volume dirty bit
file File specific commands
fsInfo File system information
hardlink Hardlink management
objectID Object ID management
quota Quota management
repair Self healing management
reparsePoint Reparse point management
storageReserve Storage Reserve management
resource Transactional Resource Manager management
sparse Sparse file control
tiering Storage tiering property management
transaction Transaction management
usn USN management
volume Volume management
wim Transparent wim hosting management
可见其是个功能十分强大的工具,不仅可以进行具体文件的管理,还可以进行配额管理,稀疏文件管理,卷轴管理等等高级操作
常规使用
想要跑哪个功能,直接在后面接这个参数,就可以看到下一层的帮助信息。例如我想要进行上面提到的File system information
,如下
C:\Windows\system32>fsutil fsinfo
---- FSINFO Commands Supported ----
drives List all drives
driveType Query drive type for a drive
ntfsInfo Query NTFS specific volume information
refsInfo Query REFS specific volume information
sectorInfo Query sector information
statistics Query file system statistics
volumeInfo Query volume information
看看我电脑上的盘符信息
C:\Windows\system32>fsutil fsinfo drives
Drives: C:\
只有一个c盘,接下来看看c盘的NTFS信息
C:\Windows\system32>fsutil fsinfo ntfsInfo c:
NTFS Volume Serial Number : 0xb6067e29067deaaf
NTFS Version : 3.1
LFS Version : 2.0
Number Sectors : 0x000000003b7627ff
Total Clusters : 0x00000000076ec4ff
Free Clusters : 0x00000000045684a1
Total Reserved : 0x00000000000016c2
Bytes Per Sector : 512
Bytes Per Physical Sector : 4096
Bytes Per Cluster : 4096
Bytes Per FileRecord Segment : 1024
Clusters Per FileRecord Segment : 0
Mft Valid Data Length : 0x0000000032440000
Mft Start Lcn : 0x00000000000c0000
Mft2 Start Lcn : 0x0000000000000002
Mft Zone Start : 0x0000000001e3b6c0
Mft Zone End : 0x0000000001e479c0
Max Device Trim Extent Count : 256
Max Device Trim Byte Count : 0xffffffff
Max Volume Trim Extent Count : 62
Max Volume Trim Byte Count : 0x40000000
Resource Manager Identifier : 2B502E06-1116-11E9-8C4E-482AE32A9B55
因为这个命令的功能过多,这里不一一展开,重点是下面的这个创建文件的功能。
快速生成指定大小文件
创建文件需要用到上面的file
参数
C:\Windows\system32>fsutil file
---- FILE Commands Supported ----
createNew Creates a new file of a specified size
findBySID Find a file by security identifier
layout Query all the information available about the file
optimizeMetadata Optimize metadata for a file
queryAllocRanges Query the allocated ranges for a file
queryCaseSensitiveInfo Query the case sensitive information for a directory
queryExtents Query the extents for a file
queryExtentsAndRefCounts Query the extents and their corresponding refcounts for a file
queryFileID Queries the file ID of the specified file
queryFileNameById Displays a random link name for the file ID
queryOptimizeMetadata Query the optimize metadata state for a file
queryValidData Queries the valid data length for a file
setCaseSensitiveInfo Set the case sensitive information for a directory
setShortName Set the short name for a file
setValidData Set the valid data length for a file
setZeroData Set the zero data for a file
setEOF Sets the end of file for an existing file
setStrictlySequential Sets ReFS SMR file as strictly sequential
需要用到第一个createNew
功能
C:\Windows\system32>fsutil file createNew
Usage : fsutil file createNew <filename> <length>
Eg : fsutil file createNew C:\testfile.txt 1000
这里直接告诉我们用法了,后面接两个参数,分别是文件完整路径和以Byte为单位的文件大小。
例如我们要在c盘生成一个10MB大小的文件,首先文件的大小为10*1024*1024=10485760,然后跑下面的命令
C:\Windows\system32>fsutil file createnew c:\10M.txt 10485760
File c:\10M.txt is created
简单快速地达到了目的
快速生成多个指定大小的文件
如果想要一次创建20个10MB大小的文件又应该如何做到呢?这里就需要用到批处理脚本来帮忙了。创建一个create_file.bat
文件,写入脚本如下
@echo off
set a=1
:loop
fsutil file createnew file%a%.txt 10485760
echo file%a% done
set /a a+=1
if %a% lss 21 goto :loop
pause
跑这个create_file.bat
文件即可在当前目录生成20个10MB大小的文件了,输出结果如下,非常快速
c:\Batch>create_file.bat
File c:\Batch\file1.txt is created
file1 done
File c:\Batch\file2.txt is created
file2 done
File c:\Batch\file3.txt is created
file3 done
File c:\Batch\file4.txt is created
file4 done
...
...
...
File c:\Batch\file18.txt is created
file18 done
File c:\Batch\file19.txt is created
file19 done
File c:\Batch\file20.txt is created
file20 done
Press any key to continue . . .
关于windows批处理命令的使用,如果大家感兴趣也欢迎关注我的csdn博客,我会做一个教程专栏分享我的一些使用心得
使用场景
目前在两个场景用到过这个创建文件的需求
- 大文件测试网速
- 特定文件大小测试硬盘配额大小
总结
Windows有fsutil
命令,在Linux中也有一个类似的命令dd
可以达到创建指定文件的目的,我会在另外一篇博客向大家分享。