Attrib – An useful windows command for noob as well as for pros

Every computer user once in their life would have come across a file were if they have a to edit that file and save it says ‘The file you want to modify is a ‘read-only’ file, do you want to save a copy of it?’ and there were also instances were the file you look for is kept ‘hidden’ either by your sysadmin or by default if it is a system file. so what are they? and how to make your file as one for your personal use? let’s see

The very basic way to change a any file into a read only file is to locate that file and right click and choose properties and then tick the read only option and hit ok but what if you want to see the attributes of that file before modification? or what if you want to select a list of files inside a folder and set attributes to all at once? then the ‘attrib’ command in your answer.

To start with first open your command prompt by going to start menu and choose ‘cmd’ and hit enter, then type ‘attrib /?’ and hit enter

 

there are a lot of options but the most common ones we use are h (hidden), r (read only) and /S /D and hence we are going to see only these options

Now for our reference we have created two text files namely ‘one’ and ‘two’ and a folder called ‘new folder’ and placed it inside a folder called ‘desktop’ on our desktop to start with first lets change the file to read only by using the regular method by going to properties and choose read only and save it as shown below

Now if we change the content of this file even by a letter or two and when we try to save it shows the pop up menu that ‘this file already exists, do you want to replace it?’

and when choosen yes it says ‘the file is a read only file try using a different name’

This tells us the read only option is in place, now we are going to apply these attributes using the command line option as discussed earlier. Before that i have removed the read only option to start fresh

Now open the command line window and type attrib then apply the read only option to that file by typing ‘attrib +r “location of that file”‘ and hit enter similarly use the hidden attribute by typing ‘+h’ to the file as shown below

After doing so if we check the attributes of that file it shows as read only and hidden since those attributes are applied

If we go to the desktop to see the file the file which was present before is now hidden as the attributes are applied

 
 

Now we are going to remove the hidden attribute by typing in ‘attrib -h “to the file we need”‘ then we can see the hidden attribute is removed as shown below

From the above we have learned to apply attributes and remove the same for the file we needed now we will see how to do the same for the folders and subfolders and the files inside it 

For this we have created two test files and one folder and placed it inside the folder named ‘desktop’ as shown below

Next we will open the command prompt and type in ‘attrib +r “folder location” /S /D’ and hit enter the /s and the /d option is used to change the attributes of a folder and also the sub folders and the files present inside it but before doing so please ensure you typed in “*.*” at the end of the command so that all the contents inside the folder will be choosen for the attributes to be applied

 

From the screenshot above we can see the read only attributes have been successfully applied to the choosen folder, files and its subfolder when the /s and /d option is used but when the read only option is removed without using the /s and /d option we can see the attribute is removed only for the choosen folder but not the contents inside them. 

Now if we try the same using the /s & /d option we can see the read only option has been removed for the choosen folder and its contents as shown below

With this we are coming to the conclusion as we have now covered all the options that were discussed and learned how to use the attrib command for our choosen files and folders.

This is especially handy when you have to apply attributes to a lot of files and folders if you are a sysadmin or if you are the mr. geek for your family at home. Hope this article was useful to you all and will see you people with another interesting post soon. 

Thanks for reading

Leave a comment