Attrib is a command to displays, sets, or removes attributes assigned to files or directories. If used without parameters, attrib displays attributes of all files in the current directory.

 

Attrib command syntax

 

The attrib command has a large number of possible options which makes it very powerful and flexible.

 

The syntax of the attrib command is as follows:

 

Syntax

attrib [{+|-}r] [{+|-}a] [{+|-}s] [{+|-}h] [{+|-}i] [<drive>:][<path>][<filename>] [/s [/d] [/l]]

 

ATTRIB command parameters

 

 

Table I. Attrib Options

PARAMETER

DESCRIPTION

{+|-}r

Sets (+) or clears (-) the Read-only file attribute.

{+\|-}a

Sets (+) or clears (-) the Archive file attribute. This attribute set marks files that have changed since the last time they were backed up. Note that the xcopy command uses archive attributes.

{+\|-}s

Sets (+) or clears (-) the System file attribute. If a file uses this attribute set, you must clear the attribute before you can change any other attributes for the file.

{+\|-}h

Sets (+) or clears (-) the Hidden file attribute. If a file uses this attribute set, you must clear the attribute before you can change any other attributes for the file.

{+\|-}i

Sets (+) or clears (-) the Not Content Indexed file attribute.

[<drive>:][<path>][<filename>]

Specifies the location and name of the directory, file, or group of files for which you want to display or change attributes.

You can use the ? and * wildcard characters in the filename parameter to display or change the attributes for a group of files.

/s

Applies attrib and any command-line options to matching files in the current directory and all of its subdirectories.

/d

Applies attrib and any command-line options to directories.

/l

Applies attrib and any command-line options to the Symbolic Link, rather than the target of the Symbolic Link.

/?

Displays help at the command prompt. 

 

Examples

 

To display the attributes of a file named example.doc that is located in the current directory, type:

 

      C:\temp>attrib example.doc

A C:\temp>example.doc

 

To assign the Read-only attribute to the file named example.doc, type:

 

      C:\temp>attrib +r example.doc

 

To remove the Read-only attribute from files in the public directory and its subdirectories on a disk in drive b:, type:

 

      attrib -r b:\public\*.* /s

 

To set the Archive attribute for all files on drive a:, and then clear the Archive attribute for files with the .bak extension, type:

 

      attrib +a a:*.* & attrib -a a:*.bak

 

Command attrib