By using attrib command, you can easily Change file attributes. In this tutorial you will learn, what is file attribute? What is the use of attrib command? what are attrib commands? How to use attrib command to Change file attributes?
What is file attribute?
According to Wikipedia, File attribute is a meta data associated with computer file that define file system behaviour. You may get doubt that what is meta data. In simple words, meta data may be file extension or file permissions. You can get more details in Wikipedia.
In Microsoft Windows, there are four attributes “archieve, read-only, hidden and system”. You can set or clear any one of these four attributes to a file. You can also set or clear all attributes to a file. To set or clear these attributes, you need to use attrib command.
What is the use of attrib command?
You can use this command to delete virus manually. Usually you can not delete virus files with delete button. Because those files may contain “hidden” or “system” or “read-only” file attribute. When you remove those file attribute from virus file, you can easily delete with delete button. You need to use attrib command to remove those file attributes.
This command will not only help you to delete virus but also to hide your file or to create read-only files.
What is attrib command syntax?
Here is the attrib command syntax,
attrib [+ | – attribute] [drive][path][file name] [/s][/d]
You need to replace “attribute” with H or S or A or R. You can also use this command without last two letters (/S and /D).
- Use +R to make file read only. When you apply this attribute, no one will edit or delete the file.
- Use -R to remove read only attribute.
- Use +H to hide file.
- Use -H to remove hide attribute.
- Use +S to make the file as command file used only by DOS.
- Use -S to turn off system attribute.
- Use +A to set archive attribute to a file. You can use this command along with BACKUP or XCOPY commands.
- Use -A to remove archive attribute.
- Use /S to apply attributes to sub-directories in the specified path.
- Use /D to include process folders.
How to use attrib command to Change file attributes
Among the four attributes, mostly, you may need R and H attributes. You can also use S attribute in combination with R and H attributes. Let us see, how to use attrib command with some examples. I have created a test folder in E drive. I have created three documents in side test folder. You can see the path in below figure.
Open your command prompt as administrator. Just right click on cmd, you will see option to “Run as Administrator”.
To hide trial.txt file, you need to use below command. You can replace ‘e’ with your drive letter, “test” with your folder name, “trial.txt” with your file name.
attrib +h e:\test\trial.txt
attrib +h +s e:\test\trial.txt
attrib +h +s e:\test\trial.txt /s
Though I am showing you possible options, first command is enough to Change file attributes.
To un hide trial.txt file, you need to use below command.
attrib -h e:\test\trial.txt
Like wise you can apply all attributes.
- attrib +r e:\test\trial.txt to convert file into read only file.
- attrib -r e:\test\trial.txt to remove read only attribute.
- attrib +h +r e:\test\trial.txt to apply read only and hide attribute.
- attrib -h -r e:\test\trial.txt to remove read only and hide attribute.
- attrib +h +r +s +a e:\test\trial.txt to apply four attributes.
- attrib -h -r -s -a e:\test\trial.txt to remove four attributes.
- attrib +h e:\test\*.txt* To apply hide attribute to all txt files in test folder.
- attrib -h e:\test\*.txt* To remove hide attribute from all txt files in test folder.
- attrib +h e:\test\*.* To apply hide property to all files in test folder
- attrib -h e:\test\*.* To remove hide property from all files in test folder
- attrib +h e:\test\test2 To hide test2 folder in test folder.
- attrib -h e:\test\test2 To unhide test2 folder in test folder from ‘E’ drive.
Thanks for reading my article about Change File Attributes With Attrib Command. If you like it, do me favor by sharing it with your friends. If you know any other method to Change file attributes, do share in comment section.