The Fsutil file in Windows

The Fsutil file finds a file by the user name (if Disk Quotas is enabled), the query allocates the scope to a file, sets the short name to a file, sets the valid data length of the file, sets the data zero for a file, or create a new file.

Applies to : Windows Server (Semi-Annual Channel), Windows Server 2016, Windows Server 2012 R2, Windows Server 2012. Windows 10, Windows 8.1, Windows 8, Windows Server 2008 R2, Windows 7.

The Fsutil file finds a file by the user name (if Disk Quotas is enabled), the query allocates the scope to a file, sets the short name to a file, sets the valid data length of the file, sets the data zero for a file, or create a new file.

For an example of how to use this command, please see the example below.

Syntax command Fsutil file

 fsutil file [createnew] fsutil file [findbysid] fsutil file [optimizemetadata] [/A] fsutil file [queryallocranges] offset= length= fsutil file [queryextents] [/R] [ []] fsutil file [queryfileid] fsutil file [queryfilenamebyid] fsutil file [queryoptimizemetadata] fsutil file [queryvaliddata] [/R] [/D] fsutil file [seteof] fsutil file [setshortname] fsutil file [setvaliddata] fsutil file [setzerodata] offset= length= 

Parameters

Parameters Create description Create file with the specified name and size, with the content consisting of 0. Specify the full path to the file including file name and extension, for example C: documentsfilename.txt. Specifies the valid length of the file. findbysid Find files that belong to a specified user on NTFS drives in which the Disk Quota feature is enabled. Specify the user name or username of the user. Specify the full path to the directory, for example C: users. optimizemetadata This performs an immediate compression of the metadata of a given file. / A File metadata analysis before and after optimization. queryallocranges Query the allocated ranges for a file on an NTFS drive. Useful to determine whether a file has sparse areas or not. offset = Specifies the beginning of the range to be set to numbers 0. length = Specifies the length of the range (in bytes). queryextents Extended query for a file. / R If it is a reparse point, open it rather than its goal. Specify the first VCN for the query. If omitted, start at VCN 0. The number of VCNs to query. If omitted or the number equals to 0, the query until EOF. queryfileid

Query the ID file for a file on the NTFS drive.

This parameter applies to: Windows Server 2008 R2 and Windows 7.

Specify the drive name following the colon. queryfilenamebyid

Displays the random link name for the ID file specified on the NTFS drive. Because a file may have more than one link name pointing to it, it is not guaranteed which file link will be provided as a result of the query for the file name.

This parameter applies to: Windows Server 2008 R2 and Windows 7.

Specify the ID of the file on the NTFS drive. queryoptimizemetadata Query the metadata status of the file. queryvaliddata Query valid data length for a file. / D Displays detailed data details. seteof Set the EOF of the specified file. setshortname Set a short name (8.3 file length of a file name) for a file on an NTFS drive. Specify the short name of the file. setvaliddata Set a valid data length for a file on an NTFS volume. Specify the length of the file, in bytes. setzerodata Sets a range (specified by Offset and Length) of the file to 0s and will empty the file. If this is a sparse file, the basic allocation units will be destroyed.

Note

  1. In NTFS, there are two IMPORTANT concepts about file lengths: End-of-file (EOF) marker and Valid Data Length (VDL). EOF indicates the actual length of the file. VDL determines the length of valid data on the drive. Any reads between VDL and EOF will automatically return 0 to preserve the C2 object reuse requirement.
  2. The setvaliddata parameter is only available to administrators because it requires privilege to perform disk maintenance tasks (SeManageVolumePrivilege). This feature is only required for advanced network and multimedia network scenarios. The parameter setvaliddata must be a positive value greater than the current VDL, but smaller than the current file size.
  3. It is very useful for programs to set up a VDL when:
    1. Write raw clusters directly to the drive via hardware channel. This allows the program to notify the file system that this range contains valid data that can be returned to the user.
    2. Create large files when performance is a problem. This avoids the time required to fill in the zero into files when the file is created or expanded.

For example

To find the file owned by Scottb on drive C, enter:

 fsutil file findbysid scottb c:users 

To query the allocated ranges for a file on an NTFS volume, enter:

 fsutil file queryallocranges offset=1024 length=64 c:tempsample.txt 

To optimize metadata for a file, enter:

 fsutil file optimizemetadata C:largefragmentedfile.txt 

To query the extension of a file, enter:

 fsutil file queryextents C:Tempsample.txt 

To set EOF for a file, enter:

 fsutil file seteof C:testfile.txt 1000 

To set short name for file Longfilename.txt on drive C to Longfile.txt, enter:

 fsutil file setshortname c:longfilename.txt longfile.txt 

To set the valid data length to 4096 bytes for a file named Testfile.txt on an NTFS drive, enter:

 fsutil file setvaliddata c:testfile.txt 4096 

To set the scope of a file on an NTFS volume to zero to empty the file, enter:

 fsutil file setzerodata offset=100 length=150 c:tempsample.txt 

See more:

  1. Fsutil command in Windows
  2. Fsutil 8dot3name command in Windows
  3. Forfiles command in Windows
3.9 ★ | 13 Vote