Set read-only attribute from command line

We can mark a file as read-only from command line too. Command for this is given below.

attrib +R  filename


attrib +R example.doc

The above command will set the read only attribute for the file file.doc and user will not be able to do modifications to the file.

To check if a file has read only attribute set, you can check by running attrib command on the file.

 attrib filename


D:\data\> attrib example.doc
A    R       D:\data\example.doc

Recursively set read-only attribute for all files in the directory

attrib /S +R