|

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

I want toType this
See the attributes of a fileattrib report.txt
Make a file read-onlyattrib +r report.txt
Remove read-only from a fileattrib -r report.txt
Remove read-only from every file in a folder treeattrib -r b:\public\*.* /s
Make a OneDrive file always available offlineattrib +p
Show every file in the current folderattrib

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

  1. Press the Windows key and type **cmd**.
  2. Select **Command Prompt**.
  3. 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] [:][][] [/s [/d] [/l]].

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

NotationMeaning
Plain textType 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

SwitchWhat it sets or clears
rThe Read-only attribute.
aThe Archive attribute, which marks files changed since the last backup.
sThe System attribute.
hThe Hidden attribute.
oThe Offline attribute.
iThe Not Content Indexed attribute.
xThe Scrub attribute.
pThe Pinned attribute.
uThe Unpinned attribute.
bThe 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

SwitchWhat it does
/sApplies the command to matching files in the current directory and all its subdirectories.
/dApplies the command to directories as well.
/lApplies 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 stateAttribute stateCommand
Always availablePinnedattrib +p
Locally availableClear pinattrib -p
Online-onlyUnpinnedattrib +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

GoalCommand
Display the attributes of a fileattrib news86
Give a file the Read-only attributeattrib +r report.txt
Remove Read-only from files in a folder and its subfoldersattrib -r b:\public\*.* /s
Set Archive on all files, then clear it for .bak filesattrib +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.

  1. Open Command Prompt as described above.
  2. Type attrib report.txt to check the attributes it currently has.
  3. Type attrib -s -h report.txt to clear System and Hidden first.
  4. Type attrib +r report.txt to make your change, in this case Read-only.
  5. Type attrib report.txt again 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.

Leave a Reply

Your email address will not be published. Required fields are marked *