fsutil - Inspect and Manage the File System
Table of Contents
The fsutil command inspects file systems such as NTFS and performs low-level operations on them. It handles tasks that are awkward with ordinary commands, such as checking free disk space, creating a file of a specific size, checking hard links, and checking volume status.
You use fsutil by following it with a subcommand and then more specific instructions.
Most fsutil subcommands fail with an error such as “Access is denied” unless you run them in a Command Prompt opened as administrator. Try the examples in this article in an elevated Command Prompt. See the related article for how to run as administrator.
Basic syntax of fsutil
fsutil <subcommand> [<operation>] [<arguments>]
The main subcommands are as follows.
| Subcommand | What it does |
|---|---|
volume | Check free space on a volume, and more |
file | File-level operations, such as creating a file of a given size |
hardlink | Create and list hard links |
dirty | Check whether a volume is marked “dirty” |
fsinfo | List drives and show volume and file system information |
behavior | Check and change file system behavior settings |
Running fsutil alone, or a subcommand without the rest (such as fsutil file), displays a list of usage information.
fsutil
fsutil file
Check free disk space
fsutil volume diskfree followed by a drive name shows that drive’s free space in bytes.
fsutil volume diskfree C:
The item names, number separators, and number of items vary with the Windows display language and version. The output above is only an example.
Unlike File Explorer, fsutil displays raw bytes rather than GB. One GB is 1,073,741,824 bytes, so dividing the displayed number by about 1 billion gives a rough figure in GB.
Check free space in a batch file
Free-space values far exceed the 32-bit integer limit (about 2 GB), so set /a cannot calculate them. For this purpose, calculating in PowerShell is the reliable approach.
@echo off
rem Show the free space on C: in GB
powershell -NoProfile -Command "[math]::Round((Get-PSDrive C).Free / 1GB, 1)"
Because the item names in fsutil output change with the display language, we do not recommend processing it as text in a batch file.
The last line of dir output also shows the free bytes on the drive that holds the folder. It requires no administrator rights and is handy, so dir is enough if you only want to check.
Create a dummy file of a specific size
fsutil file createnew quickly creates a file with the number of bytes you specify. The file is filled entirely with zeros (null characters).
fsutil file createnew <file name> <size in bytes>
fsutil file createnew dummy.bin 1048576

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
This is useful when you need a file of a known size for testing, such as trying an upload size limit or reproducing a low-disk-space situation.
| Desired size | Bytes to specify |
|---|---|
| 1 KB | 1024 |
| 1 MB | 1048576 |
| 100 MB | 104857600 |
| 1 GB | 1073741824 |
If a file with the same name already exists, fsutil file createnew fails with an error. The file is not overwritten, so you do not need to worry about damaging an existing file.
See the related article for how to create an empty (0-byte) file.
List and create hard links
A hard link is a mechanism that gives one file’s data multiple names (paths). fsutil hardlink list shows every name attached to the specified file.
fsutil hardlink list sample.txt
Paths are shown without the drive name, and only names on the same volume are listed. To create a hard link, use fsutil hardlink create.
fsutil hardlink create <new name> <existing file>
fsutil hardlink create C:\backup\sample-link.txt C:\work\sample.txt
If you only need to create a hard link, mklink /H does the same thing. mklink can also create symbolic links and junctions; see the related article for details. A hard link can only be created within the same NTFS volume.
Check volume status (dirty)
fsutil dirty query checks whether a drive is in a dirty (possibly inconsistent) state. A volume becomes dirty when the file system was not closed properly, for example because of a forced shutdown or a power failure.
fsutil dirty query C:
A dirty drive is checked automatically, for example at the next startup. To check manually, use chkdsk.
Show the drive list and volume information
fsutil fsinfo shows details about connected drives and volumes.
fsutil fsinfo drives
fsutil fsinfo volumeinfo C:
fsutil fsinfo ntfsinfo C:
Use ntfsinfo when you want to check internal NTFS information, such as bytes per cluster.
Check file system settings (behavior)
fsutil behavior query shows file system behavior settings.
fsutil behavior query disablelastaccess
fsutil behavior query disable8dot3
Changing settings with fsutil behavior set affects the behavior of the whole system. Most settings take effect after a restart. Checking with query is safe, but if you change a setting, make sure you understand it first and, if possible, create a restore point beforehand.
Summary
| What you want to do | Command |
|---|---|
| Check free space on a drive | fsutil volume diskfree C: |
| Create a dummy file of a set size | fsutil file createnew dummy.bin 1048576 |
| List hard links | fsutil hardlink list sample.txt |
| Create a hard link | fsutil hardlink create new-name existing-file |
| Check the dirty state | fsutil dirty query C: |
| List drives | fsutil fsinfo drives |
| Show volume details | fsutil fsinfo volumeinfo C: |