Microsoft DOS attrib command

Quick links

About attrib
Availability
Attrib syntax
Examples
Extended Information

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. Note: if you need to change the ACL of a file see the CACLS command.

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 back up.

Hidden - makes files invisible to standard users and hidden if show hidden files is enabled.

System - makes the file an important system file.

Note: With new versions of Windows (e.g. Windows 7 and 8) there are additional attrib options not mentioned in the above list. See the Syntax for your version of Windows to get all available options.

Availability

The attrib.exe command is an external command that is available in the below Microsoft operating systems.

MS-DOS 3.0 and above
Windows 95
Windows 98
Windows ME
Windows NT
Windows 2000
Windows XP
Windows Vista
Windows 7
Windows 8

Syntax

Windows 7 and Windows 8 syntax
Microsoft Windows 2000 and Windows XP syntax
Microsoft Windows 2000 and Windows XP recovery console syntax
Microsoft Windows 95, 98, and ME 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][filename] [/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] filename] [/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 below options 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 filename

+ 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]filename] [/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.

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.

MS-DOS and Windows command line attrib command

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, when we type attrib by itself, we can see that 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 so it cannot be modified until the read-only attribute is taken off. This 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

Most users never need to deal with a files bit position or hex value. However, for those needing this information when working with MS-DOS and the Windows command line below are the file attributes bit positions and Hex 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