attrib 0

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)

  1. R – This command will assign the “Read-Only” attribute to your selected files or folders.
  2. H – This command will assign the “Hidden” attribute to your selected files or folders.
  3. A – This command will prepare your selected files or folders for “Archiving.”
  4. 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.

  1. The + and – indicate whether you will activate or deactivate the attribute specified.
  2. The attributes you can use are those explained above.
  3. The “/S” signifies that you want to search the entire path specified including subfolders for a particular file.
  4. The “/D” signifies that you want to include any process folders as well.
  5. 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.

attrib 1

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.”

attrib 2

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.

attrib 3

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

attrib 4

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.

attrib 6

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

attrib 7

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

attrib 8

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

attrib 9

Once you press “Enter,” the entire folder will disappear since it will be hidden.

attrib 10

Now you can play with some of the other settings to make changes to any file attributes on your computer.

Profile Photo for Martin Hendrikx Martin Hendrikx
Martin Hendrikx has been writing about technology for years. His freelance career includes everything from blog posts and news articles to eBooks and academic papers.
Read Full Bio »