Microsoft DOS attrib command
About attrib
Attrib allows a user to change the attributes of a file or files. With attrib, you can change any of the add or remove any of the attributes below.
Read-only - Allows the file to be only viewed and not written to or changed.
Archived - Allows Microsoft Backup and other backup programs to know what files to backup.
Hidden - Makes files invisible to standard users and hidden if show hidden files is not enabled.
System - Makes the file an important system file.
Note: With new versions of Windows (e.g., Windows 7, 8, and 10) there are additional attrib options not mentioned in the above list. See the syntax for your version of Windows to get all available options.
Note: If you need to change the ACL of a file see the CACLS command.
Availability
The attrib command is an external command that is available in the below Microsoft operating systems attrib.exe.
- MS-DOS 3.0 and above
- Windows 95
- Windows 98
- Windows ME
- Windows NT
- Windows 2000
- Windows XP
- Windows Vista
- Windows 7
- Windows 8
- Windows 10
Syntax
Windows 7 and Windows 8 syntax
Displays or changes file attributes.
ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I] [drive:][path][file name] [/S [/D] [/L]]
+ | Sets an attribute. |
- | Clears an attribute. |
R | Read-only file attribute. |
A | Archive file attribute. |
S | System file attribute. |
H | Hidden file attribute. |
I | Not content indexed file attribute. |
X | No scrub file attribute |
V | Integrity attribute. |
/S | Processes matching files in the current folder and all subfolders. |
/D | Process folders as well. |
/L | Work on the attributes of the symbolic link versus the target of the symbolic link. |
See our attrib examples for information and examples on how to use this command.
Microsoft Windows 2000 and Windows XP syntax
Displays or changes file attributes.
ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [[drive:] [path] file name] [/S [/D]]
+ | Sets an attribute. |
- | Clears an attribute. |
R | Read-only file attribute. |
A | Archive file attribute. |
S | System file attribute. |
H | Hidden file attribute. |
/S | Processes files in all directories in the specified path. |
/D | Process folders as well. |
See our attrib examples for information and examples on how to use this command.
Microsoft Windows 2000 and Windows XP recovery console syntax
Note: The options below are the available options in the Windows recovery console.
Changes attributes on one file or directory.
ATTRIB -R | +R | -S | +S | -H | +H | -C | +C [file name]
+ | Sets an attribute. |
- | Clears an attribute. |
R | Read-only file attribute. |
S | System file attribute. |
H | Hidden file attribute. |
C | Compressed file attribute. |
See our attrib examples for information and examples on how to use this command.
Microsoft Windows 95, 98, and ME syntax
Displays or changes file attributes.
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [[drive:][path]file name] [/S]
+ | Sets an attribute. |
- | Clears an attribute. |
R | Read-only file attribute. |
A | Archive file attribute. |
S | System file attribute. |
H | Hidden file attribute. |
/S | Processes files in all directories in the specified path. |
Attrib examples
attrib
Typing attrib by itself displays all files in the current directory and each of their attributes. If any file is hidden, it also displays those files.
As can be seen in the above example, we typed the dir command to list the files in the current directory and could only see the "computer.bat" file listed. However, if you type attrib by itself, there are three files in this directory, "computer.bat" with read-only, "example.txt" with hidden, and "hope.txt" with the hidden and read-only attribute.
attrib +r autoexec.bat
Add the read-only attribute to the autoexec.bat file to prevent it from being modified until the read-only attribute is taken off. This command is helpful for important system files or any other file that you do not want to have mistakenly edited or changed by another program.
attrib +h config.sys
Add the hidden attribute to the config.sys file, causing it to be not be seen by the average user.
attrib -h config.sys
This command does the opposite of the example shown before this command. Instead of hiding the file this command makes the file visible if hidden.
attrib +r +h autoexec.bat
Finally, this example adds two attributes to the autoexec.bat and makes the file read-only as well as hidden.
Extended information
Below is the MS-DOS and the Windows command line file attributes bit positions and hexadecimal values with bit positions in the order of "7 6 5 4 3 2 1 0."
Bit Positions | Hex | Description |
---|---|---|
0 0 0 0 0 0 0 1 | 01h | Read-only file |
0 0 0 0 0 0 1 0 | 02h | Hidden file |
0 0 0 0 0 1 0 0 | 04h | System file |
0 0 0 0 1 0 0 0 | 08h | Volume Label |
0 0 0 1 0 0 0 0 | 10h | Subdirectory |
0 0 1 0 0 0 0 0 | 20h | Archive |
0 1 0 0 0 0 0 0 | 40h | Reserved |
1 0 0 0 0 0 0 0 | 80h | Reserved |
Examples | ||
0 0 1 0 0 0 0 1 | 21h | Read-only, Archive |
0 0 1 1 0 0 1 0 | 32h | Hidden, Subdirectory, Archive |
0 0 1 0 0 1 1 1 | 27h | Read-only, Hidden, System file, Archive |
0 0 1 0 0 0 1 1 | 23h | Read-only, Hidden, Archive |
Additional information
- See our ACL, file attributes, and permission definitions for further information and related links on these terms.