A+ Certification / Beginners

Setting basic attributes

As with so many other areas of the operating system, where there are many different ways to achieve your goal, there are many different ways to change the attributes of files. The first method - using the command line - is the only way that is common to all of the Microsoft operating systems; but we will also show you how to set attributes using the Windows GUI.

Command line

In order to change file attributes from the command line, you will have to get to the Command Prompt window by choosing Start → All Programs → Accessories → Command Prompt, which will open a Command Prompt window. To set attributes you have to use the attrib.exe command. The basic syntax for the command is this:

attrib <attribute to set (H, S, R, A)> <files to modify>

Setting of the attributes includes a plus (+) or minus (-) sign, specifying whether the attribute should be enabled (a plus) or disabled (a minus), followed by a one-letter code for each attribute. For example, to set the read only attribute and remove the archive attribute from the C:\boot.ini file, you would type, attrib.exe +R -A C:\boot.ini. The one-letter codes are as follows:

  • H: Hidden
  • S: System
  • R: Read-only
  • A: Archive

If you use the attrib command without any options, it will display a list of the current attributes of all the files in the current directory. Here is a sample of what that would look like:

C:\>attrib.exe
A 	C:\7flen.crt
A SHR 	C:\arcldr.exe
A SHR 	C:\arcsetup.exe
A 	C:\AUTOEXEC.BAT
A SH 	C:\boot.ini
A 	C:\CONFIG.SYS
A SHR 	C:\IO.SYS
A SHR 	C:\MSDOS.SYS
A SHR 	C:\NTBOOTDD.SYS
A SHR 	C:\NTDETECT.COM
A SHR 	C:\ntldr
A 	C:\uninst.log

If you use the attrib.exe command with options but without specifying a filename, you will set the attribute(s) for all the files in the current directory. Here is an example of the command and the attributes that would be set:

C:\>attrib.exe -A -S -H -R
	C:\7flen.crt
	C:\arcldr.exe
	C:\arcsetup.exe
	C:\AUTOEXEC.BAT
	C:\boot.ini
	C:\CONFIG.SYS
	C:\IO.SYS
	C:\MSDOS.SYS
	C:\NTBOOTDD.SYS
	C:\NTDETECT.COM
	C:\ntldr
	C:\uninst.log

You can specify a file after the attrib command to see the current attributes of that file, or you can include the one-letter codes to set the attribute(s), like this:

C:\>attrib.exe C:\config.sys
A 	C:\CONFIG.SYS
C:\>attrib.exe +h +r C:\config.sys
C:\>attrib.exe C:\config.sys
A HR 	C:\CONFIG.SYS

Another option you can include with the attrib.exe command is /s, which instructs attrib.exe to process the files in all subdirectories - this does not change the attribute on the subdirectories, just the files in the subdirectories. If you are using Windows 2000 or newer Windows OS, then /d will change the attributes of the directories as well.

There are some restrictions on changing attributes with the attrib.exe command. Hidden and System files will not have their attributes changed, unless the current Hidden or System attribute is also specified in a single command. Examine the following command sequence, which shows an example of dealing with Hidden or System files.

C:\>attrib.exe -S -H -A -R C:\config.sys

C:\>attrib.exe C:\config.sys
	C:\config.sys

C:\>attrib.exe +S C:\config.sys

C:\>attrib.exe +R C:\config.sys
Not resetting system file - C:\config.sys

C:\>attrib.exe C:\config.sys
  S 	C:\config.sys

C:\>attrib.exe +R +S C:\config.sys

C:\>attrib.exe C:\config.sys
  S R 	C:\config.sys

C:\>attrib.exe +H C:\config.sys
Not resetting system file - C:\config.sys

C:\>attrib.exe +H +S C:\config.sys

C:\>attrib.exe C:\config.sys
  SHR 	C:\config.sys

C:\>attrib.exe -S -H -R C:\config.sys

C:\>attrib.exe C:\config.sys
	C:\config.sys

Windows GUI

In addition to the command line interface for changing attributes, Windows offers a GUI interface. When you right-click a file, you only see the options for Read-only, Hidden, and Archive when working with FAT partitions. If you are working with NTFS partitions, then the Archive check box is replaced with an Advanced button.

Clicking the Advanced button lets you set the Archive attribute as well as the Windows 2000/XP advanced attributes of Index, Compress, and Encrypt.

[Previous] [Contents]