LOGO

Change File Attributes with Attrib in Windows Command Prompt

January 1, 2015
Change File Attributes with Attrib in Windows Command Prompt

Utilizing the 'attrib' Command in Windows

The Windows operating system provides a comprehensive suite of utilities accessible through the command prompt. Among these is the attrib tool, a powerful function for managing file attributes.

Understanding File Attributes

With attrib, users can locate files based on their name and directory. It then allows for the viewing and alteration of specific characteristics associated with those files.

These attributes define how a file is handled by the system. They control aspects like whether a file is hidden, read-only, or a system file.

How to Access and Use the 'attrib' Tool

The attrib command is directly available within the Windows command prompt environment. It’s a built-in utility, requiring no separate installation.

To employ the tool, simply open the command prompt and type “attrib” followed by the desired parameters. These parameters specify the file or directory and the attributes to be viewed or modified.

Key Functionality of the 'attrib' Command

  • Viewing Attributes: You can display the current attributes of a file or folder.
  • Modifying Attributes: The tool enables changes to attributes such as read-only, hidden, and system settings.
  • Searching by Name and Location: Files can be targeted for attribute modification based on their name and the directory they reside in.

Effectively using attrib provides granular control over file management within the Windows environment. This is particularly useful for system administrators and advanced users.

Understanding Available Attributes

With your elevated command prompt now active, it's crucial to understand the different attributes that can be modified using the “attrib” utility. These attributes fall into two primary categories: basic and extended.

The “attrib” command allows for precise control over file and folder properties.

Basic Attribute Options (R, H, A, S)

Several fundamental attribute switches are available for immediate use.

  • R – Read-Only: Applying this switch designates the chosen files or directories as read-only, preventing modifications.
  • H – Hidden: This attribute conceals the selected files or folders from standard directory listings.
  • A – Archive: Setting the archive attribute marks files or folders as available for backup or archiving processes.
  • S – System: Assigning the system attribute typically identifies files or folders as critical components of the operating system.

These basic switches provide essential control over file visibility and modification permissions.

Understanding the “Attrib” Command Syntax

Before utilizing the attrib tool, it’s essential to familiarize yourself with its correct syntax.

ATTRIB [+ attribute | - attribute] [pathname] [/S [/D]]

A clear understanding of the various switches and parameters within this syntax is crucial for effective command execution.

Key Components of the Syntax

  • The + and - symbols denote the activation or deactivation of a specific attribute, respectively.
  • Available attributes are those previously detailed.
  • The /S switch instructs the command to recursively search the specified path, including all subdirectories, for matching files.
  • Utilizing the /D switch extends the search to encompass directories as well.
  • The pathname defines the location of the target file or folder.

Properly formatted pathnames are demonstrated below.

Drive and/or filename - C:\*.* OR C:\Users\Owner\Desktop\samplefile.txt

Should no attributes be explicitly defined, the files or folders will return to their pre-existing attribute configurations.

Attribute Modification Behavior

When no attribute is specified, the attrib command will reset the file or folder to its default attribute settings.

Practical Exercises with File Attributes

Having explored the various attributes available and the necessary syntax, let's solidify your understanding through practical application. Begin by accessing the Command Prompt in Windows 7 or 10 via the Start menu, or utilize the search functionality in Windows 8 and type "CMD." Subsequently, right-click on the search result and select "Run as administrator." While an elevated command prompt isn't strictly required, it minimizes potential confirmation prompts.

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-1.jpg

Scenario 1: Removing “Hidden” and “System” Attributes to Restore File Visibility.

As a demonstration, we will first generate a file named “sample.txt” within your “Documents” directory. To do this, navigate to the directory, right-click within the window, select “New,” then “Text File,” and assign the name “sample” to the newly created document.

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-2.jpg

Now, switch to your CMD window. We will modify the file’s properties to designate it as both a system file and a hidden file. This is achieved by executing the following command.

attrib +h +s C:\Users\Martin\Documents\sample.txt

Ensure you replace “Martin” in the path with your actual computer username.

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-3.jpg

Upon execution, the file will become invisible within your documents folder. To revert this and remove the System and Hidden attributes from “sample.txt,” employ the following command.

attrib –h –s C:\Users\Martin\Documents\sample.txt

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-4.jpg

It’s crucial to include the complete file path in your command; omitting it will result in an error. Returning to your “Documents” directory will reveal the file once more.

Scenario 2: Setting Multiple Text Files to Read-Only and System Attributes.

We will now create several sample text files within the “Downloads” directory and utilize the “attrib” tool to configure them all as read-only system files.

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-5.jpg

With your sample text files created, it’s time to use CMD to execute a command that alters the attributes of all text files in the specified directory to “Read-Only and System.” Wildcards will be used to select all text files. This can be accomplished using the command below. Remember to substitute “Martin” with your computer’s username.

attrib +r +s C:\Users\Martin\Downloads\*.txt

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-6.jpg

You can then open your downloads folder, right-click on a text file, and select “Properties” to verify the attribute changes. To undo these settings, use the same command, but replace the plus signs with minus signs.

attrib -r -s C:\Users\Martin\Downloads\*.txt

Scenario 3 – Marking a File for Archiving.

Begin by creating a sample text file on your desktop. Then, navigate to your CMD window and enter the following command to prepare the selected file for archiving.

attrib +a C:\Users\Martin\Desktop\sample.txt

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-7.jpg

Scenario 4 - Concealing an Entire Directory/Folder on Your Desktop.

Imagine you have sensitive data within a folder named “Private” on your desktop and wish to hide it, including all its contents. It’s important to note that when dealing with directory attributes, wildcards like “?” and “*” cannot be used. You must specify the complete file path. First, create a folder on your desktop and populate it with some files. Once completed, navigate to your CMD window and enter the following command.

attrib +h C:\Users\Martin\Desktop\Private

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-8.jpg

Pressing “Enter” will cause the entire folder to disappear, as it will be hidden.

how-to-change-file-attributes-with-attrib-from-the-windows-command-prompt-9.jpg

You are now equipped to experiment with other settings and modify file attributes on your computer as needed.

#attrib#command prompt#windows#file attributes#hidden files#read-only