Windows – ATTRIB command – How to manage file attributes?

Windows maintains file attributes to manage the files in the File System. These attributes will be useful to control the files; for example, deleting the read-only files will prompt to get the confirmation to delete them.

By using ATTRIB command from the command prompt, we can manage the file attributes of the file(s).

Display file attributes

If you just type the ATTRIB command without passing any arguments from the command prompt, it will display the attributes of each file in the current directory.

C:\>attrib
             C:\run.bat
A  SHR       C:\bootmgr
A  SH        C:\pagefile.sys

Above command displays the attributes associated with each file. Each attribute represents with the specific symbol. If none of the attributes are set to the file, you will see a blank space for the file. For example, from above result for “run.bat” none of the attributes are set; and you see a blank space as an attribute result.

Below are the attributes and the representation of it with the special symbol in ATTRIB command.

R – Represents for read-only file attribute

H – For hidden file attribute

S – Represents system file attribute

A – Represents ready for archive attribute

Now we can read the above result as below.

“run.bat” – Does’t have any attributes set.

“bootmgr” has Archive, System, Hidden and Read-only attributes set. And

“pagefile.sys” file has Archive, System and Hidden attributes set.

Set file attributes

Plus symbol (“+”) is used to add attributes to the files through ATTRIB command. Along with plus symbol (“+”) you need to specify the type of attribute to add to the file(s) by specifying the associated attribute symbol (mentioned above). For example, to make a file as read-only file, you can use the command like below;

C:\> attrib +r sample.txt

This command allows to set attributes at a time to multiple files(s) by using the wildcard characters. For example, to make all the text files, which have extension “.txt”, are read-only; you can use the ATTRIB command like below;

C:\> attrib +r *.txt

This command also allows to apply multiple attributes at a time to the file(s). Each attribute to apply to the file(s), should be mentioned separately and separate them by a blank space. For example, below command applies multiple attributes to the file(s) with the extension “.doc”.

C:\> attrib +r +h +a *.doc

Clears file attributes

You can also clear the file attributes set for the files using ATTRIB command. To clear the attributes, you need to use minus symbol (“-“) and the related attributes. For example, to clear the attributes set by above command for the document files (“*.doc”) can be reset using the below command;

C:\> attrib -r -h -a *.doc

Be on learning path always!

// Malin

Windows – ATTRIB command – How to manage file attributes?

Leave a Reply

Your email address will not be published.

Scroll to top