Windows File System

The Windows file system is the structure Windows uses to name, store, organize, and protect data on storage devices.
Windows supports several file systems, each with different capabilities designed for security, performance, reliability, or compatibility with other devices.
Today, NTFS is used for the Windows system drive, while FAT32 and exFAT are mostly used for USB drives and memory cards, and ReFS is used for servers and developer storage.

File System Types

Name Descriptions
FAT32 [File Allocation Table 32-bit] Legacy file system [introduced in 1996], supported by almost every device and operating system.
Maximum file size: 4 GB [minus 1 byte] - larger files cannot be copied to a FAT32 drive.
Windows' built-in tools have traditionally limited new FAT32 partitions to 32 GB [newer Windows 11 builds raise this to 2 TB when using the format command].
No journaling, no file permissions, and no built-in encryption.
Ideal for small USB flash drives, and devices that only support FAT32 [older cameras, game consoles, car stereos, UEFI boot partitions].
NTFS [New Technology File System] The default file system for Windows since Windows XP, and required for the Windows system drive.
Supports very large files and volumes [256 TB in practice, up to 8 PB on recent Windows versions with large cluster sizes, 16 EB in theory].
Built-in file and folder permissions using Access Control Lists [ACLs], and file ownership.
Supports metadata journaling, file compression, file-level encryption [EFS], disk quotas, hard links, symbolic links, and Alternate Data Streams [ADS].
Readable on macOS and Linux, but writing to it from those systems may require additional drivers.
Ideal for system drives, internal disks, and large external drives used only with Windows.
exFAT [Extended File Allocation Table] Designed for removable flash storage [USB drives, SD cards, external SSDs], and the standard file system for SDXC memory cards.
Supports very large files [no 4 GB limit like FAT32].
Supported natively by Windows, macOS, and Linux, which makes it the best choice for sharing large files between different operating systems.
Lacks NTFS features such as permissions, encryption, and journaling - unplugging the drive without ejecting it can corrupt data.
ReFS [Resilient File System] A newer Microsoft file system [introduced with Windows Server 2012], designed for data integrity and very large storage.
Uses checksums for metadata [and optionally for file data] to detect corruption.
When used with Storage Spaces mirror or parity volumes, it can automatically repair corrupted data while the volume stays online.
Supports volumes and files up to 35 PB, and fast block cloning, which is especially useful for virtual machines.
Does not support some NTFS features, such as EFS encryption, and Windows cannot be installed on a ReFS volume.
Mainly used in Windows Server, and on Windows 11 through Dev Drive - a ReFS volume optimized for developer workloads.

Windows File System Hierarchy

Unlike Linux, which uses a single directory tree starting at root [/], Windows gives each volume its own drive letter [C:\, D:\, E:\],
and each drive has its own directory tree. [Volumes can also be mounted into an empty NTFS folder instead of a drive letter, but this is less common.]
Structure of a typical Windows file system:

Root Directories [Drive Letters]:
Each volume is assigned a drive letter. The C:\ drive is usually the system partition where Windows is installed.
The letters A:\ and B:\ were historically reserved for floppy disk drives, which is why the system drive is C:\.

System Directories:
C:\Windows\ – Contains the core operating system files [also referred to by the environment variable %SystemRoot%].
C:\Program Files\ – The default installation location for 64-bit applications.
C:\Program Files (x86)\ – The installation location for 32-bit applications on 64-bit Windows.
C:\ProgramData\ – A hidden folder that stores application data and settings shared by all users.
C:\Users\ – Contains the profile folder of every user on the system, plus a Public folder shared by all users.
C:\Windows\Temp\ – Temporary files used by Windows and system services.

User Directories:
C:\Users\[Username]\ – The user's profile folder [%USERPROFILE%].
C:\Users\[Username]\Desktop\, Documents\, Downloads\, Pictures\ – The user's personal folders.
C:\Users\[Username]\AppData\ – A hidden folder that stores user-specific application data, divided into three subfolders:
Local\ – Data that stays on this computer only, such as caches. It also contains the user's temporary folder, AppData\Local\Temp [%TEMP%].
LocalLow\ – Data for applications that run with low integrity [restricted permissions], such as sandboxed browser components.
Roaming\ – Settings that follow the user between computers when roaming profiles are used in a domain environment [%APPDATA%].

Hidden and System Files:
C:\pagefile.sys – The Windows paging file, used as virtual memory when physical RAM is full.
C:\swapfile.sys – A smaller paging file used by modern [Store] apps.
C:\hiberfil.sys – The hibernation file, which stores the contents of RAM when the computer hibernates [also used by Fast Startup].
C:\$Recycle.Bin\ – Recycle Bin storage, with a separate subfolder for each user [named after the user's SID].
C:\System Volume Information\ – Stores System Restore points and Volume Shadow Copies. Accessible only by the SYSTEM account.
C:\Windows\System32\ – Critical system files, programs, and libraries. On 64-bit Windows, this folder contains the 64-bit files, despite its name.
C:\Windows\SysWOW64\ – Contains the 32-bit system files on 64-bit Windows [WOW64 stands for "Windows 32-bit on Windows 64-bit"].

Important Locations for Security & Forensics

These locations are commonly checked by SOC analysts and incident responders, and commonly abused by attackers:
C:\Windows\System32\config\ – The registry hives, including SAM [local user accounts and password hashes], SYSTEM, SECURITY, and SOFTWARE.
C:\Windows\System32\winevt\Logs\ – The Windows Event Logs [.evtx files], such as Security.evtx, System.evtx, and Application.evtx.
C:\Windows\System32\drivers\etc\hosts – The local hosts file. Malware sometimes modifies it to redirect or block websites.
C:\Windows\Prefetch\ – Prefetch files [.pf] that show which programs were executed, and when - a valuable source of evidence in investigations.
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\ – Programs placed here run automatically when the user logs in - a common persistence location.
%TEMP%, C:\Users\Public\, and C:\ProgramData\ – Writable without administrator rights, so malware often drops and runs files from these folders.

File System Features

Access Control and Security

NTFS uses Access Control Lists [ACLs] to define which users and groups can access each file and folder, and what they are allowed to do.
Windows offers two types of encryption:
EFS [Encrypting File System] - Encrypts individual files and folders on NTFS, tied to the user's account and certificate.
BitLocker - Encrypts an entire volume, protecting all data if the disk or computer is stolen. Available on Pro, Enterprise, and Education editions [Windows Home offers a simpler "Device Encryption"].
BitLocker works below the file system, so it can protect NTFS, FAT32, and exFAT volumes [BitLocker To Go for USB drives].

Journaling and Data Integrity

NTFS uses a transaction log [$LogFile] to record metadata changes before they are written, so the file system can quickly recover to a consistent state after a crash or power loss.
NTFS journaling protects the file system structure, not the contents of your files.
NTFS also keeps a separate Change Journal [$UsnJrnl], which records every file creation, deletion, and rename - very useful in forensic investigations.
ReFS takes a different approach: instead of overwriting metadata in place, it writes changes to a new location [allocate-on-write], and uses checksums to detect corruption.

Compression

NTFS supports built-in, transparent file compression - files are compressed on disk and decompressed automatically when opened.
It can be enabled from the file's Properties > Advanced, or with the compact command.
A file cannot be both NTFS-compressed and EFS-encrypted at the same time.

Alternate Data Streams [ADS]

NTFS allows a file to contain more than one stream of data. The normal content is the main stream, and additional hidden streams can be attached to it.
These hidden streams do not change the file size shown in File Explorer, and are invisible to normal directory listings.
Windows itself uses ADS for the "Mark of the Web" - a stream called Zone.Identifier that marks files downloaded from the internet, which triggers security warnings.
Attackers can abuse ADS to hide data or malicious code inside legitimate files.
You can view streams with dir /r in CMD, or Get-Item [file] -Stream * in PowerShell.

Shadow Copies and Backups

The Volume Shadow Copy Service [VSS] creates point-in-time snapshots of a volume, even while files are in use.
It is used by System Restore, File History, Windows Backup, and most third-party backup software.
From a security perspective, ransomware almost always tries to delete shadow copies before encrypting files, to prevent recovery
[for example, with vssadmin delete shadows /all /quiet] - this command is a strong indicator of a ransomware attack.

File Attributes

Windows files and folders have special attributes that control their behavior and visibility.
These attributes can be managed through File Explorer [Properties], or with command-line tools such as attrib, compact, and cipher.

Common File Attributes

Attribute Description
Read-Only [R] Prevents a file from being modified.
Deleting it requires confirmation in File Explorer, or the /f switch with the del command.
On folders, Windows ignores this attribute [it is used internally to mark customized folders].
Hidden [H] Hides files and folders from File Explorer and the dir command by default.
Can be viewed by enabling "Hidden items" in File Explorer's View menu, or with dir /a.
Note: Hidden is not a security feature - anyone can still open hidden files.
System [S] Marks files as critical operating system files.
Usually combined with the Hidden attribute, and hidden even when "Hidden items" is enabled, unless "Hide protected operating system files" is turned off.
Should not be modified without proper knowledge.
Archive [A] Indicates that a file has been created or modified since the last backup.
Set automatically by Windows, and cleared by backup software after the file is backed up.
Not Content Indexed [I] Excludes the file from Windows Search indexing.
Compressed [C] Indicates that the file is compressed by NTFS to save disk space.
Only available on NTFS volumes.
Files are automatically decompressed when opened, and compressed again when saved.
Encrypted [E] The file is encrypted using EFS [Encrypting File System].
Accessible only by the user who encrypted it, users they share it with, and designated recovery agents.
Important: back up your EFS certificate [with the cipher /x command] - if it is lost, the files cannot be recovered.

NTFS Permissions and Ownership

NTFS provides granular control over file and folder access through permissions and ownership.
Each file and folder has an Access Control List [ACL], made up of entries [ACEs] that Allow or Deny specific permissions to users and groups.
Understanding these concepts is crucial for system security and multi-user environments.

Standard NTFS Permissions

Permission Levels

Permission Capabilities
Full Control Complete access to files and folders.
Can read, write, modify, delete, change permissions, and take ownership.
Modify Can read, write, modify, execute, and delete files and folders.
Cannot change permissions or take ownership.
Read & Execute Can view file contents and run programs and scripts.
Cannot modify or delete files.
List Folder Contents Folder-only permission.
Can view the names of files and subfolders, and browse into subfolders.
Read Can view file contents, attributes, and permissions.
Cannot run programs or make changes.
Write Can create new files and folders, and change the contents and attributes of existing files.
Cannot delete files [deleting requires Modify].

Permission Inheritance

Child folders and files inherit permissions from their parent folder by default.
This simplifies permission management across large directory structures.
Inheritance can be disabled for specific folders that require custom permissions.

How Windows Decides Access

Permissions from all of a user's groups are combined - if any group is allowed, the user is allowed, unless a Deny entry applies.
An explicit Deny takes priority over an explicit Allow.
Permissions set directly on a file [explicit] take priority over inherited permissions - so an explicit Allow can override an inherited Deny.
When accessing files over the network, both the Share permissions and the NTFS permissions apply, and the more restrictive of the two wins.

Ownership

Every file and folder has an owner - usually the user who created it.
The owner can always change the file's permissions, even if they have been denied access.
Administrators can take ownership of any file [with the takeown or icacls /setowner commands], which is how locked-out files are recovered.

Permissions From a Security Perspective

Weak permissions are one of the most common ways attackers escalate privileges on Windows.
For example, if a regular user can modify a program that runs as a service with SYSTEM privileges, they can replace it with their own code.
Tools like WinPEAS automatically search for these misconfigurations, and you can check a file's permissions yourself with icacls [file].

File System Commands

Windows provides powerful command-line tools for file system management.
These commands can be executed in Command Prompt [CMD] or PowerShell. Commands that change system files or other users' files require an Administrator prompt.

Essential CMD Commands

Command Prompt File Operations

Command Purpose
dir Lists files and directories in the current location.
dir /a - Shows all files, including hidden and system files.
dir /s - Lists the contents of all subdirectories.
dir /r - Shows Alternate Data Streams.
cd [path] Changes the current directory.
cd .. - Moves up one directory level.
cd \ - Returns to the root of the current drive.
cd /d D:\Folder - Changes to a folder on another drive.
tree Displays the folder structure as a tree.
tree /f - Includes the files in each folder.
type [filename] Displays the contents of a text file.
copy [source] [dest] Copies files from source to destination.
copy *.txt D:\ - Copies all .txt files to the D drive.
xcopy [source] [dest] Copies files and directory trees.
xcopy /s /e - Copies directories and subdirectories, including empty ones.
Note: xcopy is deprecated - use robocopy instead.
robocopy [source] [dest] "Robust File Copy" - the recommended tool for copying large folders, with retry and resume support.
robocopy C:\Data D:\Backup /e - Copies all subfolders, including empty ones.
robocopy C:\Data D:\Backup /mir - Mirrors the source [WARNING: deletes files in the destination that don't exist in the source].
move [source] [dest] Moves files and directories.
ren [old] [new] Renames a file or directory.
del [filename] Deletes one or more files [files deleted from the command line do not go to the Recycle Bin].
del /f - Forces deletion of read-only files.
mkdir [name] Creates a new directory.
md [name] - Short form of the same command.
rmdir [name] Removes an empty directory.
rmdir /s - Removes a directory and all of its contents.
rmdir /s /q - Does the same without asking for confirmation.
attrib Displays or changes file attributes.
attrib +h file.txt - Makes a file hidden.
attrib -r file.txt - Removes the read-only attribute.
attrib -h -s file.txt - Removes the hidden and system attributes.
icacls [file] Displays or changes NTFS permissions.
icacls file.txt /grant User:R - Gives a user Read permission.
icacls folder /reset /t - Resets permissions to the inherited defaults.
takeown /f [file] Takes ownership of a file [Administrator required].
takeown /f folder /r - Takes ownership of a folder and everything inside it.
compact Displays or changes NTFS compression.
compact /c file.txt - Compresses a file.
cipher Displays or changes EFS encryption.
cipher /e folder - Encrypts a folder.
cipher /w:C:\ - Overwrites deleted data in free space so it cannot be recovered.
chkdsk [drive] Checks a disk for file system errors.
chkdsk C: /f - Fixes errors on the C drive [may require a restart].
chkdsk C: /r - Locates bad sectors and recovers readable data [includes /f].
fsutil Advanced file system utility [Administrator required].
fsutil fsinfo volumeinfo C: - Shows file system information for a volume.
vssadmin Manages Volume Shadow Copies [Administrator required].
vssadmin list shadows - Lists the existing shadow copies.
diskpart Advanced disk partitioning and management utility.
Requires administrative privileges.
Used for creating, deleting, formatting, and managing partitions. WARNING: Mistakes can erase entire disks.
format [drive] Formats a disk for use with Windows.
format D: /fs:NTFS - Formats the D drive with the NTFS file system.
format D: /fs:exFAT /q - Quick format with exFAT.
WARNING: Deletes all data on the drive.

PowerShell Commands

PowerShell File System Operations

Command Purpose
Get-ChildItem Lists files and directories [aliases: dir, ls, gci].
Get-ChildItem -Force - Includes hidden and system files.
Get-ChildItem -Recurse - Lists all subdirectories.
Get-ChildItem -Recurse -Filter *.log - Finds all .log files.
Set-Location [path] Changes the current directory [aliases: cd, sl].
Get-Content [file] Displays the contents of a file [aliases: cat, type, gc].
Get-Content file.log -Tail 20 -Wait - Shows the last 20 lines and follows new lines as they are written.
Copy-Item Copies files and directories [aliases: copy, cp].
Copy-Item -Recurse - Copies with subdirectories.
Move-Item Moves files and directories [aliases: move, mv].
Rename-Item Renames a file or directory [alias: ren].
Remove-Item Deletes files and directories [aliases: del, rm].
Remove-Item -Recurse - Deletes a directory and its contents.
New-Item Creates new files or directories.
New-Item -ItemType Directory - Creates a folder.
New-Item -ItemType File - Creates a file.
Test-Path [path] Checks whether a file or folder exists [returns True or False].
Get-Acl / Set-Acl Retrieves or sets the access control list [permissions] of files and folders.
Get-Acl file.txt | Format-List - Shows the owner and all permissions.
Get-Item [file] -Stream * Lists all data streams of a file, including Alternate Data Streams.
Get-Content [file] -Stream Zone.Identifier - Shows where a downloaded file came from.
Unblock-File [file] Removes the "Mark of the Web" from a downloaded file.
Get-FileHash [file] Calculates a file's hash [SHA256 by default] - used to verify downloads and look up suspicious files on VirusTotal.
Get-Volume Displays information about volumes [drive letter, file system, size, free space, health].
Repair-Volume Scans or repairs a volume [the PowerShell equivalent of chkdsk].
Repair-Volume -DriveLetter C -Scan - Scans for errors without taking the volume offline.

Sources: Microsoft Learn - ReFS overview, Microsoft Learn - Dev Drive, Microsoft Learn - format command.

▲
▼