By using the attrib command, you can easily Change file attributes. In this tutorial you will learn, what is the 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, the File attribute is a metadata associated with computer file that defines file system behaviour. You may get a doubt that what is metadata. In simple words, metadata 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 the virus manually. Usually, you can not delete virus files with the 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 the 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 the archive attribute.
- Use /S to apply attributes to sub-directories in the specified path.
- Use /D to include process folders.
How to use the attrib command to Change file attributes?
Among the four attributes, mostly, you may need R and H attributes. You can also use the S attribute in combination with R and H attributes. Let us see, how to use the attrib command with some examples. I have created a test folder in E drive. I have created three documents inside the test folder. You can see the path in the 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, the 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 a file into a 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 the test folder.
- attrib -h e:\test\*.txt* To remove hide attribute from all txt files in the 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 the comment section.