Attrib is a DOS command that is used to change the attributes of a file or group of files. There are four basic attributes that you can modify with Attrib: read-only (R), system (S), hidden (H), and archive (A). Files either have each of these attributes or they don't, and you can turn the attributes on or off.
The read-only attribute means a file can not be modified (by most applications). If you try to edit a read-only file from the command prompt, a message will be displayed stating that the file can not be modified. If you try to edit the same file in Windows, you can make changes to it, but you won't be able to save the file.
Files with the system attribute are system files that should generally be left alone. If you try to change the other attributes of a system file from the command line, you'll see the "Not resetting system file" message. In order to change a system file's other attributes, you'd have to remove the system attribute, change what you wanted to change, and then put the system attribute back.
Files that are hidden can not be viewed by the dir command or seen in Windows Explorer (unless you have Windows set to show hidden files). Hiding a file can be helpful for privacy reasons, as well as to reduce apparent clutter.
The archive attribute is used for backup purposes. If a file has been changed since the last time it was backed up, it will generally have the archive attribute turned on.
To use Attrib, you must be at the command line. In Windows XP, type "cmd" in the Run bar, and in Windows Vista or 7, type it in the Search bar. (Then hit <ENTER>.) Attrib can be used several different ways.
Typing "attrib" by itself will display the files in the current directory along with their attributes. Each attribute will be represented by its first letter -- R, S, H, or A. If the letter is there, that file has that specific attribute turned on. If the letter is not there, that attribute is turned off.
To enable an attribute for one file, use the plus sign (+) and the attribute's letter. For example, to make the file "data.txt" hidden, you would type "attrib data.txt +h". You could also type "attrib +h data.txt" -- the filename can go before or after the attribute. To remove the H attribute, you would type "attrib data.txt -h".
If you wanted to make every file in the current directory read-only, you could do it by typing "attrib +r" without specifying a filename. Any file that's not marked as a system file would become read-only. If a file was already read-only, typing that command wouldn't change it at all. To remove the read-only attribute from those same files, you would type "attrib -r".
If you want to change the attributes of a file that uses spaces in its name, such as "johns data file.txt", you would need to put the filename in quotes; typing
attrib johns data file.txt +r
would result in an error message. You would need to type it as:
attrib "johns data file.txt" +r
You can alter attributes for a file anywhere on the computer, not just in the current directory, but in order to do so you would need to include the path as well as the filename (ie. "attrib c:\windows\temp\backup.dat +h").
Windows gives you some control over attributes as well, though not as much as you have from the command prompt. If you right click on a file in Windows and select Properties, you can turn on or off two of the file's attributes -- read-only and hidden. Changing either of these attributes in Windows will also affect the file's status at the command prompt.
(Originally published on Helium.com, May 2010)
No comments:
Post a Comment