attrib - Change file attributes

Maintained on

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 del command 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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib
A           C:\Users\user\document.txt
A    H      C:\Users\user\hidden.txt
        R   C:\Users\user\readme.txt
C:\users\user>

This lists the attributes of the files in the current directory.

About the attribute display

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib document.txt
A           C:\Users\user\document.txt
C:\users\user>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

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

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

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかる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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +r document.txt

document.txt can now no longer be overwritten or deleted normally.

Editing read-only files

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -r document.txt

Set the hidden attribute

Use +h to make a file hidden.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +h secret.txt

secret.txt is now not shown in File Explorer by default.

How to show hidden files

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -h secret.txt

Set multiple attributes at once

You can set several attributes at the same time. The following makes a file read-only and hidden.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +r +h important.txt

You can clear several attributes at once in the same way.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -r -h important.txt

attrib options

The attrib command has the following options.

OptionDescription
+rSets the read-only attribute
-rClears the read-only attribute
+aSets the archive attribute
-aClears the archive attribute
+sSets the system attribute
-sClears the system attribute
+hSets the hidden attribute
-hClears the hidden attribute
/sProcesses matching files in the current folder and all subfolders
/dApplies the change to folders as well
/lProcesses the symbolic link itself instead of its target
There are other attributes too

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +r *.txt /s
Batch processing

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -r logs\*.* /s /d
Check before applying widely

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.

Working with symbolic links

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).

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -s -h D:\*.* /s /d
About changing system file attributes

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +r +h important_config.txt
Read-only on folders

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:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +a document.txt

To clear it after a backup:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -a document.txt

Using wildcards

You can process several files at once with wildcards.

Make all .txt files in the current directory read-only:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +r *.txt

Clear the hidden attribute from all files in the current directory:

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib -h *.*

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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>attrib +r system.dat
Access denied - system.dat
C:\users\user>

In that case, run Command Prompt as administrator and try again. If it still fails, the file may be protected by the system.

Running as administrator

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:

  • attrib manages the read-only, hidden, system, and archive attributes
  • Use + to set an attribute and - to clear it
  • /s includes subfolders
  • /d changes folder attributes too
  • Wildcards let you process many files at once
  • Attributes are listed in the order A, S, H, R, and dir /a:h shows only hidden files

Managing file attributes properly helps you protect important files and manage files efficiently.

These articles cover other file-related commands.

Practice quiz

Practice Problem

Which command makes document.txt read-only?

回答がサーバーに送信されることはありません
Practice Problem

Which command clears the hidden attribute from all .txt files in the current folder and its subfolders?

回答がサーバーに送信されることはありません
#Command Prompt #Batch File #Command Line #Command