Attrib Command Examples Options Switches and More
Attrib Command (Examples, Options, Switches, and More) GA S REGULAR Menu Lifewire Tech for Humans Newsletter! Search Close GO Software & Apps > Windows 75 75 people found this article helpful
If you're not sure how to interpret the attrib command syntax you see above or shown in the table below, it's advised to learn how to read command syntax. Attrib Command Options Item Explanation attrib Execute the attrib command alone to see the attributes set on the files within the directory that you execute the command from. +a Sets the archive file attribute to the file or directory. -a Clears the archive attribute. +h Sets the hidden file attribute to the file or directory. -h Clears the hidden attribute. +i Sets the 'not content indexed' file attribute to the file or directory. -i Clears the 'not content indexed' file attribute. +r Sets the read-only file attribute to the file or directory. -r Clears the read-only attribute. +s Sets the system file attribute to the file or directory. -s Clears the system attribute. +v Sets the integrity file attribute to the file or directory. -v Clears the integrity attribute. +x Sets the no scrub file attribute to the file or directory. -x Clears the no scrub attribute. drive:, path, filename This is the file (filename, optionally with drive and path), directory (path, optionally with drive), or drive that you want to view or change the attributes of. Wildcard use is allowed. /s Use this switch to execute whatever file attribute display or changes you're making on the subfolders within whatever drive and/or path you've specified, or those within the folder you're executing from if you don't specify a drive or path. /d This attrib option includes directories, not only files, to whatever you're executing. You can only use /d with /s. /l The /l option applies whatever you're doing with the attrib command to the Symbolic Link itself instead of the target of the Symbolic Link. The /l switch only works when you're also using the /s switch. /? Use the help switch with the attrib command to show details about the above options right in the Command Prompt window. Executing attrib /? is the same as using the help command to execute help attrib. In Recovery Console, +c and -c switches apply to attrib. They set and clear the compressed file attribute, respectively. Outside of this diagnostic area in Windows XP, use the compact command to handle file compression from the command line. When a wildcard is allowed with attrib, it means that you can use an asterisk to apply the attribute to a group of files. However, if applicable, you have to clear the system or hidden attribute first before you can change any of the file's other attributes.
In the above example, attrib turns on the read-only attribute, using the +r option, for the secretfolder directory located in c:\windows\system. attrib -h c:\config.sys
In this example, the config.sys file located in the root directory of the c: drive has its hidden file attribute cleared by use of the -h option. attrib -h -r -s c:\boot\bcd
This time, attrib removes several file attributes from the bcd file, an important file that must be working for Windows to start. In fact, executing the attrib command, as shown above, is a key part of the process outlined in the steps necessary for rebuilding the BCD in Windows. attrib +a f:*.* & attrib -a f:*.bak With the above example, we're applying +a to set the archive attribute on all files that exist on the f: drive, but then using & to remove the archive attribute on every file on f: that has the .bak file extension. In the above example, BAK files indicate files that have already been backed up, meaning that they don't need to be archived/backed up again, hence the need to remove the archive attribute. attrib myimage.jpg
To end with a simple attrib example, this one simply displays the attributes of a file named myimage.jpg. If you were to remove the second half and execute only the attrib command, it would display the attributes for all files in the current directory.
Attrib Command (Examples, Options, Switches, and More)
Change the attributes of a file or folder with this shell command
By Tim Fisher Tim Fisher Senior Vice President & Group General Manager, Tech & Sustainability Emporia State University Tim Fisher has more than 30 years' of professional technology experience. He's been writing about tech for more than two decades and serves as the VP and General Manager of Lifewire. lifewire's editorial guidelines Updated on December 13, 2020 Reviewed by Chris Selph Reviewed by Chris Selph Chris Selph is a CompTIA-certified technology and vocational IT teacher. He also serves as network & server administrator and performs computer maintenance and repair for numerous clients. lifewire's editorial guidelines Tweet Share Email Tweet Share EmailIn This Article
Expand Jump to a Section Attrib Command Availability Syntax & Switches Examples Errors Changes in the Attrib Command Related Commands Viewing Attributes in Explorer The attrib command displays or changes the file attributes for a file or folder. It's run from the Command Prompt in all versions of Windows. Derek Abella / Lifewire' Attrib' Command Availability
The attrib command is available in the Command Prompt in all Windows operating systems including Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, plus older versions of Windows as well. All offline diagnostic and repair tools available with the various versions of Windows, including Advanced Startup Options, System Recovery Options, and Recovery Console, also include attrib in some capacity. This attrib command is also available in MS-DOS as a DOS command. The availability of certain attrib command switches and other attrib command syntax might differ from operating system to operating system.' Attrib' Command Syntax & Switches
The command takes the following general form: attrib [+a-a] [+h-h] [+i-i] [+r-r] [+s-s] [+v-v] [+x-x] [drive:][path][filename] [/s [/d] [/l]]If you're not sure how to interpret the attrib command syntax you see above or shown in the table below, it's advised to learn how to read command syntax. Attrib Command Options Item Explanation attrib Execute the attrib command alone to see the attributes set on the files within the directory that you execute the command from. +a Sets the archive file attribute to the file or directory. -a Clears the archive attribute. +h Sets the hidden file attribute to the file or directory. -h Clears the hidden attribute. +i Sets the 'not content indexed' file attribute to the file or directory. -i Clears the 'not content indexed' file attribute. +r Sets the read-only file attribute to the file or directory. -r Clears the read-only attribute. +s Sets the system file attribute to the file or directory. -s Clears the system attribute. +v Sets the integrity file attribute to the file or directory. -v Clears the integrity attribute. +x Sets the no scrub file attribute to the file or directory. -x Clears the no scrub attribute. drive:, path, filename This is the file (filename, optionally with drive and path), directory (path, optionally with drive), or drive that you want to view or change the attributes of. Wildcard use is allowed. /s Use this switch to execute whatever file attribute display or changes you're making on the subfolders within whatever drive and/or path you've specified, or those within the folder you're executing from if you don't specify a drive or path. /d This attrib option includes directories, not only files, to whatever you're executing. You can only use /d with /s. /l The /l option applies whatever you're doing with the attrib command to the Symbolic Link itself instead of the target of the Symbolic Link. The /l switch only works when you're also using the /s switch. /? Use the help switch with the attrib command to show details about the above options right in the Command Prompt window. Executing attrib /? is the same as using the help command to execute help attrib. In Recovery Console, +c and -c switches apply to attrib. They set and clear the compressed file attribute, respectively. Outside of this diagnostic area in Windows XP, use the compact command to handle file compression from the command line. When a wildcard is allowed with attrib, it means that you can use an asterisk to apply the attribute to a group of files. However, if applicable, you have to clear the system or hidden attribute first before you can change any of the file's other attributes.
Attrib Command Examples
attrib +r c:\windows\system\secretfolderIn the above example, attrib turns on the read-only attribute, using the +r option, for the secretfolder directory located in c:\windows\system. attrib -h c:\config.sys
In this example, the config.sys file located in the root directory of the c: drive has its hidden file attribute cleared by use of the -h option. attrib -h -r -s c:\boot\bcd
This time, attrib removes several file attributes from the bcd file, an important file that must be working for Windows to start. In fact, executing the attrib command, as shown above, is a key part of the process outlined in the steps necessary for rebuilding the BCD in Windows. attrib +a f:*.* & attrib -a f:*.bak With the above example, we're applying +a to set the archive attribute on all files that exist on the f: drive, but then using & to remove the archive attribute on every file on f: that has the .bak file extension. In the above example, BAK files indicate files that have already been backed up, meaning that they don't need to be archived/backed up again, hence the need to remove the archive attribute. attrib myimage.jpg
To end with a simple attrib example, this one simply displays the attributes of a file named myimage.jpg. If you were to remove the second half and execute only the attrib command, it would display the attributes for all files in the current directory.