Skip to main content This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
attrib
- Article
- 2 minutes to read
In this article
Displays, sets, or removes attributes assigned to files or directories. If used without parameters, attrib displays attributes of all files in the current directory.
Syntax
attrib [{+|- }r] [{+|- }a] [{+|- }s] [{+|- }h] [{+|- }i] [<drive>:][<path>][<filename>] [/s [/d] [/l]]
Parameters
Parameter | Description |
---|---|
{+|- }r |
Sets (+) or clears (—) the Read-only file attribute. |
{+\|- }a |
Sets (+) or clears (—) the Archive file attribute. This attribute set marks files that have changed since the last time they were backed up. Note that the xcopy command uses archive attributes. |
{+\|- }s |
Sets (+) or clears (—) the System file attribute. If a file uses this attribute set, you must clear the attribute before you can change any other attributes for the file. |
{+\|- }h |
Sets (+) or clears (—) the Hidden file attribute. If a file uses this attribute set, you must clear the attribute before you can change any other attributes for the file. |
{+\|- }i |
Sets (+) or clears (—) the Not Content Indexed file attribute. |
[<drive>:][<path>][<filename>] |
Specifies the location and name of the directory, file, or group of files for which you want to display or change attributes. You can use the ? and * wildcard characters in the filename parameter to display or change the attributes for a group of files. |
/s | Applies attrib and any command-line options to matching files in the current directory and all of its subdirectories. |
/d | Applies attrib and any command-line options to directories. |
/l | Applies attrib and any command-line options to the Symbolic Link, rather than the target of the Symbolic Link. |
/? | Displays help at the command prompt. |
Examples
To display the attributes of a file named News86 that is located in the current directory, type:
attrib news86
To assign the Read-only attribute to the file named report.txt, type:
attrib +r report.txt
To remove the Read-only attribute from files in the public directory and its subdirectories on a disk in drive b:, type:
attrib -r b:\public\*.* /s
To set the Archive attribute for all files on drive a:, and then clear the Archive attribute for files with the .bak extension, type:
attrib +a a:*.* & attrib -a a:*.bak
Additional References
- Command-Line Syntax Key
- xcopy command
Feedback
Submit and view feedback for
File attributes are special metadata or properties of files stored in the file system which instruct computer software to change its behavior. Some of them may be enforced by operating system. For example, the read-only attribute prevents apps from writing to such files and tells File Explorer to warn the user that the file or folder can be important. The console DEL command doesn’t remove files with the read-only attribute. In this article, we will review different methods to change file attributes in Windows 10. Windows 10 offers the user a number of methods to change file system attributes for folders and files. Each attribute can have only one state at a moment: it can be set or disabled. While file attributes are part of file system metadata, they always considered separate from other metadata values like file date or permissions.
In Windows 10, you can use File Explorer (both the Ribbon option and the File Properties dialog), PowerShell, and the good old command prompt to modify or set file attributes. Let’s review each method in detail.
- Open File Explorer and go to the folder that contains your files.
- Select the file whose attributes you want to change.
- On the Home tab of the Ribbon, click on the Properties button.
- In the next dialog, under Attributes, you can set or remove the Read-only and Hidden attributes.
- Click on the Advanced button to set or clear extra attributes available for the file.
You are done. The extra file attributes include:
- File is ready for archiving.
- Allow this file to have contents indexed in addition to file properties.
- Compress file contents to save disk space.
- Encrypt contents to secure data.
Tip: You can open the File Properties dialog using the context menu. Right-click a file and select the Properties command. Also, you can quickly open the file properties if you press and hold the Alt key and double-click the file or press Enter. See the article: How to open file or folder properties quickly in Windows File Explorer For the «Hidden» attribute, one more way is to use the button Hide selected items in the View tab of the Ribbon. See the following article: How to hide and unhide files quickly in Windows 10.
Change file attributes with PowerShell
It is possible to change file attributes using the PowerShell console. There are a couple of cmdlets which can be used to view, set, or remove them. Here is how you can use them. Open a new PowerShell console and use the following commands. To view file attributes with PowerShell, run the following cmdlet:
Get-ItemProperty -Path path_to_file
Replace the path_to_file with the actual path to your file. The command will print all the attributes for the file. To view all of the information that is available, combine the output with the Format-List cmdlet, as shown below:
Get-ItemProperty -Path path_to_file | Format-list -Property * -Force
This will show more details about your file. To change file attributes with PowerShell, run the following cmdlet:
Set-ItemProperty -Path path_to_file -Name IsReadOnly -Value True
This will set the ReadOnly attribute for the specified file. The possible values for the -Name argument are as follows:
- Archive
- Hidden
- Normal
- ReadOnly
- System
Set the appropriate value to True to set the attribute. A value of False will clear the attribute.
Change file attributes using Command Prompt
The command prompt comes with a console attrib command which allows managing file attributes. It supports the following attributes:
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
O Offline attribute.
I Not content indexed file attribute.
X No scrub file attribute.
V Integrity attribute.
P Pinned attribute.
U Unpinned attribute.
B SMR Blob attribute.
Each attribute can be set using the syntax like this (for example, for read-only attribute):
attrib +R path_to_file
To remove the attribute, you can use the following command:
attrib -R path_to_file
So, «+» sets an attribute, and «-» clears an attribute. For example, here is how to set a hidden attribute using the command prompt. Change the hidden attribute using the command prompt
- Open a new command prompt window.
- Type the following command to set the hidden attribute:
attrib +H c:\data\myfile.txt
- To remove the attribute, use the command:
attrib -H c:\data\myfile.txt
You are done. For more information, run the attrib command as follows:
attrib /?
That’s it. Support us Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options: If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support! Windows offers a wide variety of tools that you can access using your command prompt window including the “attrib” tool which is designed to help you search for files by location and name then view and modify their file attributes.
What Attributes Can You Use?
Now that you have your elevated command prompt window open, you will need to know what types of attributes you can edit using the “attrib” tool. There are two main types of attributes, “basic” and “extended.” Basic Attribute Switches (R, H, A, S)
- R – This command will assign the “Read-Only” attribute to your selected files or folders.
- H – This command will assign the “Hidden” attribute to your selected files or folders.
- A – This command will prepare your selected files or folders for “Archiving.”
- S – This command will change your selected files or folders by assigning the “System” attribute.
“Attrib” Syntax
You will need to know the proper syntax to use for the “attrib” tool before you get started.
ATTRIB [+ attribute | - attribute] [pathname] [/S [/D]]
In this syntax, you will need to know what the different switches and parameters represent.
- The + and – indicate whether you will activate or deactivate the attribute specified.
- The attributes you can use are those explained above.
- The “/S” signifies that you want to search the entire path specified including subfolders for a particular file.
- The “/D” signifies that you want to include any process folders as well.
- The pathname indicates the location of your target folder or file. The proper syntax for path files is shown below.
Drive and/or filename - C:\*.* OR C:\Users\Owner\Desktop\samplefile.txt
If you decide not to specify any of the attributes listed above, the files or folders will revert to their current attribute settings.
Let’s Practice
Now that you know the types of attributes you can use and the syntax you need to use, let’s practice some scenarios. Open the start menu in Windows 7 and 10 or open the search function in Windows 8 and search for CMD. Next, right-click on it and then press “Run as administrator.” While you don’t need to open an elevated command prompt window, it will help you to avoid any confirmation dialog boxes. Scenario 1 – Clear “Hidden and System” attributes with a single command to make your files or folders normal. For this example, we will first create a file in your “Documents” directory called “sample.txt.” First, open up the directory and right-click somewhere in the window, move your mouse to the “New” section, click on “Text File,” and name the document “sample.”
Now go to your CMD window. We will change the file’s properties so that it is both a system file, and hidden. Do this by entering the following command.
attrib +h +s C:\Users\Martin\Documents\sample.txt
Remember to substitute the “Martin” section of the path parameter with your computer’s username. Once you have done this, you will notice that the file has disappeared from your documents folder. Now that we want to remove the System and Hidden file attributes from “sample.txt,” we will need to use the following simple command.
attrib –h –s C:\Users\Martin\Documents\sample.txt
Note that if you try to enter the file name without a path, you will receive an error. You must remember to add the entire path to your command. Now, if you go back to your “Documents” directory, you will see the file in the list. Scenario 2 – Make all text files in your “Downloads” folder read-only system files. Now we will create a few sample text files in the “Downloads” directory and we will edit them using the “attrib” tool so that they all become read-only system files.
Once you have your sample text files created, it is time to use CMD to write a command that will change the attributes of all text files in a specified directory to “Read-Only and System.” For this, we will need to use wildcards to select all the text files. You can do this by using the command below. Remember to substitute the “Martin” section with your computer’s username.
attrib +r +s C:\Users\Martin\Downloads\*.txt
Now you can open your downloads folder, right-click on one of the text files and then select properties. You will note that the file attributes have been changed. To remove these settings simply use the same command, but replace the plus signs with minus signs.
attrib -r -s C:\Users\Martin\Downloads\*.txt
Scenario 3 – Prepare a file located on your desktop for archiving. Let’s start by creating a sample text file on the desktop. Now, navigate to your CMD window and enter the following string to prepare the selected file for archiving.
attrib +a C:\Users\Martin\Desktop\sample.txt
Scenario 4 – Hide an entire Directory/Folder on your desktop. Let’s say for example, you have sensitive data in a folder on your desktop called “Private,” and you want to hide it along with all its files and subfolders. It is important to note that when you are working with directory attributes, you cannot use wildcards such as “? and *.” You will need to be explicit in your file path. First, you need to create a folder on your desktop and put a few files in it. Once you have done that, navigate to your CMD window and enter the following command.
attrib +h C:\Users\Martin\Desktop\Private
Once you press “Enter,” the entire folder will disappear since it will be hidden.
Now you can play with some of the other settings to make changes to any file attributes on your computer. READ NEXT
- › The Best VoIP Services of 2022
- › Google Pixel 7 Pro Review: The Android Smartphone to Beat
- › You’re Tracking Your Sleep Wrong
- › 8 Default Microsoft Word Settings You Should Change
- › How Much Worse Is the Xbox Series S, Really?
- › How to Add a BCC in Outlook Emails
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]]
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\secretfolder
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 Errors
As with most commands in Command Prompt, use double-quotes around a folder or file name that has spaces. If you forget to do this with the attrib command, you’ll get a «Parameter format not correct -« error.
For example, instead of typing my folder in Command Prompt to show the path to a folder by that name, you’d type «my folder» to use the quotes.
Attrib command errors like Access Denied mean that you don’t have enough access to the file(s) you’re trying to make attribute changes to. Take ownership of those files in Windows and then try again.
Changes in the Attrib Command
The +i, -i, and /l attrib command options were first available in Windows Vista and have been retained up through Windows 10.
The +v, -v, +x, and -x switches for the attrib command are only available in Windows 7, Windows 8, and Windows 10.
‘Attrib’-Related Commands
It’s common for the xcopy command to effect a file’s attribute after it backs up something. For example, the xcopy command’s /m switch turns off the archive attribute after the file has been copied.
Similarly, the xcopy /k switch keeps a file’s read-only attribute once it’s been copied.
Viewing Attributes in Explorer
You can also view and manage attributes for files and folders in Explorer using regular menu buttons. This might be preferred for you if you’re not familiar with the command line.
Do this by right-clicking the object and going into its Properties > General tab. Thanks for letting us know! Get the Latest Tech News Delivered Every Day Subscribe
- How to become a physics teacher
- How to transfer jobs
- How to enable webgl
- How to cook parboiled rice
- How to play ipad videos on tv