How to Hide a File or Make It Read-Only with attrib
Use attrib in CMD to inspect R, H, S, and A flags, hide or unhide files, and remove read-only status. Includes safe /s and /d examples.
Start Interactive LessonPeople search attrib when File Explorer will not show a file, a document is stuck as read-only, or they need to see the R/H/S/A flags from Command Prompt. attrib shows those flags and turns them on or off. Official syntax lives on Microsoft Learn: attrib. Practice the same commands in the attrib lesson.
Change an attribute, then inspect the result
What attrib shows
Run attrib with no arguments in the current folder. Windows lists files only (not folders) and prints a fully qualified path on each line, such as C:\Users\Student\welcome.txt. The left columns are:
- R — read-only (many programs will refuse to overwrite the file until you clear it)
- H — hidden (plain
dirskips it;dir /astill lists it) - S — system
- A — archive (used by backup tools)
Changing an attribute prints nothing when it succeeds. Check the file again with attrib filename.
Hide and unhide a file
attrib +h secret.txt hides the file. attrib -h secret.txt brings it back. A common miss is typing +h again instead of -h to unhide.
Explorer’s “Hidden items” checkbox only controls whether you see hidden files. The H flag stays on the file until you remove it.
Make a file read-only
Protect a notes file you do not want to overwrite:
Clear it with attrib -r notes.txt. Read-only is not encryption. Anyone who can run attrib -r can edit the file again.
Folders and subfolders
attrib +h SecretFolder hides that folder name. To walk a tree, add /s. /d includes directories; without /d, /s still targets files. Example: attrib -r -h -s *.* /s clears R/H/S on matching files under the current folder.
Bare attrib never lists directories. That is normal cmd behavior, not a broken command.
Before changing a whole tree, preview the path and scope with dir /a. /s walks matching files below the current folder; /d adds directories to that operation and requires /s. Start with one known filename, verify the result with attrib filename, and only then broaden the pattern.
Common mistake
Using + when you meant -. attrib +h file.txt twice still leaves the file hidden. Unhide with -h. Same for -r vs +r.
FAQ
How do I hide a file with attrib?
attrib +h filename
How do I unhide a file in Command Prompt?
attrib -h filename, then refresh Explorer or run dir /a.
How do I remove read-only?
attrib -r filename
What do H, R, S, and A mean? Hidden, read-only, system, and archive.
Can attrib hide every file in subfolders?
Yes: attrib +h *.* /s from the folder you want to start in. Add /d if you also want directories.
Need a longer drill? See Practical: Attributes or list hidden files with dir.
Knowledge Check
1 / 3Which flag makes a file read-only?
References
These documentation links provide authoritative details for the commands used in this article.
Up Next
Remove unwanted files forever.