How To Use The Attrib Command In Windows (2027)
Attrib shows, sets and clears the attributes on files and folders, such as Read-only and Hidden, from Command Prompt.
The basic pattern is attrib +r filename to switch an attribute on and attrib -r filename to switch it off.
This guide follows Microsoft’s attrib reference, so each switch and rule below comes from the official page.
Table of Contents
- Attrib quick answers
- What the attrib command does
- Open Command Prompt
- The attrib syntax
- How to read the syntax line
- What each attribute letter means
- View the attributes of a file
- Set or clear Read-only
- Hidden and system files come first
- Work on subfolders with /s, /d and /l
- Use wildcards for groups of files
- The Archive attribute and xcopy
- Pinned and unpinned attributes for OneDrive files
- Microsoft’s own examples
- Change a protected file step by step
- Show hidden files without the command line
- Official sources
- More Windows guides
Attrib quick answers
| I want to | Type this |
|---|---|
| See the attributes of a file | attrib report.txt |
| Make a file read-only | attrib +r report.txt |
| Remove read-only from a file | attrib -r report.txt |
| Remove read-only from every file in a folder tree | attrib -r b:\public\*.* /s |
| Make a OneDrive file always available offline | attrib +p |
| Show every file in the current folder | attrib |
What the attrib command does
Attrib displays, sets or removes the attributes assigned to files or directories.
Run on its own with no parameters, it lists the attributes of all files in the current directory.
Microsoft lists the command as available on Windows 11 and Windows 10, as well as current Windows Server releases.
Open Command Prompt
- Press the Windows key and type **cmd**.
- Select **Command Prompt**.
- Type your attrib command and press **Enter**.
If the files sit in a protected location, open Terminal as administrator first.
The attrib syntax
Microsoft gives the full syntax as attrib [{+|-}r] [{+|-}a] [{+|-}s] [{+|-}h] [{+|-}o] [{+|-}i] [{+|-}x] [{+|-}p] [{+|-}u] [{+|-}b] [.
A plus sign sets an attribute, and a minus sign clears it.
You can combine several attribute letters in one command.
How to read the syntax line
| Notation | Meaning |
|---|---|
| Plain text | Type it exactly as shown. |
| A placeholder you replace with your own value, such as a path. |
[text in square brackets] | An optional item you can leave out. |
{text in braces} | A set of required items, and you choose one. |
| (vertical bar) | Separates choices, and you pick only one. |
So {+|-}r means you must type either +r or -r, and every attribute group in the syntax line is optional.
What each attribute letter means
| Switch | What it sets or clears |
|---|---|
r | The Read-only attribute. |
a | The Archive attribute, which marks files changed since the last backup. |
s | The System attribute. |
h | The Hidden attribute. |
o | The Offline attribute. |
i | The Not Content Indexed attribute. |
x | The Scrub attribute. |
p | The Pinned attribute. |
u | The Unpinned attribute. |
b | The SMR Blob attribute. |
View the attributes of a file
Type the command with only a file name to display its attributes.
Microsoft’s example is attrib news86, which shows the attributes of that file in the current directory.
Use the drive and path in front of the name to check a file somewhere else.
Set or clear Read-only
To lock a file against changes, run attrib +r report.txt.
To make it editable again, run attrib -r report.txt.
Microsoft’s example for a whole folder is attrib -r b:\public\*.* /s, which clears Read-only on the files in that directory and its subdirectories.
Hidden and system files come first
Microsoft states that a file with the System attribute must have it cleared before you can change any other attribute on that file.
The same rule applies to the Hidden attribute.
So to change a hidden system file, clear those two first with attrib -s -h filename, then make your other change.
To hide a file, set the attribute with attrib +h filename.
Work on subfolders with /s, /d and /l
| Switch | What it does |
|---|---|
/s | Applies the command to matching files in the current directory and all its subdirectories. |
/d | Applies the command to directories as well. |
/l | Applies the command to a symbolic link itself, not to the target it points to. |
/? | Shows help in the Command Prompt window. |
Use wildcards for groups of files
The file name part accepts the ? and * wildcard characters.
The * stands for any run of characters and the ? for a single character, so *.bak matches every file with that extension.
This lets one command change the attributes of a whole group of files.
The Archive attribute and xcopy
The Archive attribute marks files that have changed since they were last backed up.
Microsoft notes that the xcopy command uses this attribute, so setting or clearing it changes which files an archive-based copy picks up.
Microsoft’s example sets Archive on every file on drive a:, then clears it for files with the .bak extension: attrib +a a:*.* & attrib -a a:*.bak.
To see how that copy side works, read the Xcopy command guide.
Pinned and unpinned attributes for OneDrive files
The Pinned and Unpinned switches control the Files On-Demand state of a cloud-synced file.
| Files On-Demand state | Attribute state | Command |
|---|---|---|
| Always available | Pinned | attrib +p |
| Locally available | Clear pin | attrib -p |
| Online-only | Unpinned | attrib +u |
Pinning an online-only file makes the sync app download its contents, and unpinning a downloaded file frees the space it used on the device.
Microsoft also says that to set an online-only file to locally available, you must first set it to always available.
To check the current state of a file or folder, run attrib followed by its path.
Microsoft’s own examples
| Goal | Command |
|---|---|
| Display the attributes of a file | attrib news86 |
| Give a file the Read-only attribute | attrib +r report.txt |
| Remove Read-only from files in a folder and its subfolders | attrib -r b:\public\*.* /s |
| Set Archive on all files, then clear it for .bak files | attrib +a a:*.* & attrib -a a:*.bak |
Change a protected file step by step
This walk-through uses a file named report.txt that has both the Hidden and System attributes.
- Open Command Prompt as described above.
- Type
attrib report.txtto check the attributes it currently has. - Type
attrib -s -h report.txtto clear System and Hidden first. - Type
attrib +r report.txtto make your change, in this case Read-only. - Type
attrib report.txtagain to confirm the new attributes.
Do not skip the third step, because Microsoft requires the System and Hidden attributes to be cleared before any other attribute on that file can be changed.
Only set System on a file again if you know it is meant to be a system file, and leave the Hidden attribute off unless you want the file out of normal folder listings.
Show hidden files without the command line
If you only want to see hidden files, File Explorer can do that without typing commands.
The steps are in the guide to showing file extensions and hidden files.
Official sources
Every switch above comes from Microsoft’s attrib reference.
The Files On-Demand commands come from Microsoft’s Files On-Demand states page.
Syntax notation is explained in the Command-Line Syntax Key.
More Windows guides
- How To Use The Cipher Command In Windows (2026)
- How To Use The Bcdedit Command In Windows (2026)
- How To Use The Xcopy Command In Windows (2026)
- How To Use The Gpupdate Command In Windows (2026)
- How To Use The Robocopy Command In Windows (2027)
- How To Use The Tasklist And Taskkill Command In Windows (2027)
See all: Windows 11 Guides