attrib - Change file attributes
When working with files and folders in Command Prompt or batch files, you sometimes need to check or change file attributes.
The attrib command lets you easily change attributes such as read-only, hidden, system, and archive.
This article explains the attrib command from basic usage to practical examples.
What is the attrib command?
The attrib command displays and changes the attributes of files and folders.
Windows files can have the following attributes:
- Read-only (R): The file cannot be overwritten, and the
delcommand refuses to delete it normally - Hidden (H): The file is not shown in File Explorer by default
- System (S): Marks an important file used by the Windows system
- Archive (A): Used by backup software to detect files that have changed
Setting these attributes appropriately lets you protect important files or temporarily hide them.
Basic usage
The basic syntax of the attrib command is as follows.
attrib [+attribute | -attribute] [filename] [/S] [/D]
The simplest use is to run attrib without a file name.
This lists the attributes of the files in the current directory.
Attributes are shown as letters in the order Archive (A), System (S), Hidden (H), Read-only (R). A blank is shown in the position of any attribute that is not set. Hidden files are also listed.
Check the attributes of a specific file
To check a specific file, specify its name.

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Setting and clearing attributes
Use the + sign to set an attribute and the - sign to clear it.
Set the read-only attribute
Use +r to make a file read-only.
document.txt can now no longer be overwritten or deleted normally.
Trying to overwrite a read-only file causes an error. Clear the read-only attribute before editing. Read-only is only a safeguard against accidents: del /f can still delete read-only files, so it is not a security feature.
Clear the read-only attribute
Use -r to clear the read-only attribute.
Set the hidden attribute
Use +h to make a file hidden.
secret.txt is now not shown in File Explorer by default.
In File Explorer, turn on “Hidden items” in the View menu to see hidden files. In Command Prompt, dir /a:h lists only hidden files. Hiding a file is not enough as a security measure.
Clear the hidden attribute
Use -h to clear the hidden attribute.
Set multiple attributes at once
You can set several attributes at the same time. The following makes a file read-only and hidden.
You can clear several attributes at once in the same way.
attrib options
The attrib command has the following options.
| Option | Description |
|---|---|
+r | Sets the read-only attribute |
-r | Clears the read-only attribute |
+a | Sets the archive attribute |
-a | Clears the archive attribute |
+s | Sets the system attribute |
-s | Clears the system attribute |
+h | Sets the hidden attribute |
-h | Clears the hidden attribute |
/s | Processes matching files in the current folder and all subfolders |
/d | Applies the change to folders as well |
/l | Processes the symbolic link itself instead of its target |
Current versions of Windows support more attributes, such as offline and not-content-indexed. For everyday file work, knowing R, A, S and H is enough.
The /s option - include subfolders
The /s option processes files in subfolders as well.
The following makes all .txt files in the current folder and its subfolders read-only.
Combining /s with wildcards lets you change the attributes of many files at once.
The /d option - include folders
With /d, the change is applied to folders as well as files. Combined with /s, folders in subfolders are included too.
The following clears the read-only attribute from all files and folders under the logs folder.
A command such as attrib +h *.* /s /d hides a large number of files at once. Always check the target folder first, and try it on a small folder.
Use the /l option to change the attributes of the symbolic link itself rather than its target.
Practical examples
Clear system and hidden attributes
When a USB drive is infected by a virus, files are sometimes changed to hidden or system files.
The following clears the system and hidden attributes from all files and folders on drive D (the USB drive).
Changing the attributes of genuine Windows system files may stop the system from working properly. Do not use this command on the system drive (usually C:).
Protect important files from accidents
Set the read-only attribute on files you do not want to overwrite or delete by mistake. Adding the hidden attribute also reduces accidents in File Explorer.
Setting read-only on a folder does not restrict editing or deleting the files inside it. It is a special attribute used for folder display settings, so to protect the files inside, set the attribute on the files with /s (e.g., attrib +r folder\*.* /s).
Mark files for backup
The archive attribute is used by backup software to detect changed files. It is set automatically when a file is modified.
To set it manually:
To clear it after a backup:
Using wildcards
You can process several files at once with wildcards.
Make all .txt files in the current directory read-only:
Clear the hidden attribute from all files in the current directory:
Errors and fixes
Access denied
When you try to change the attributes of a system file or a protected file, you may see an “Access denied” error.
In that case, run Command Prompt as administrator and try again. If it still fails, the file may be protected by the system.
Search for “cmd” in the Start menu, right-click “Command Prompt”, and choose “Run as administrator”.
Summary
This article explained how to view and change file attributes with the attrib command.
Key points:
attribmanages the read-only, hidden, system, and archive attributes- Use
+to set an attribute and-to clear it /sincludes subfolders/dchanges folder attributes too- Wildcards let you process many files at once
- Attributes are listed in the order A, S, H, R, and
dir /a:hshows only hidden files
Managing file attributes properly helps you protect important files and manage files efficiently.
Related commands
These articles cover other file-related commands.