How to Change File Attributes with Attrib

Attrib is a command used to change the various characteristics or attributes of a file or directory in DOS, OS/2 and Microsoft Windows. It generally displays, sets or removes the read-only, archive, system, and hidden attributes of a file or directory. So here is a tutorial to Save, Hide, Archive files using Attrib command.

Basic Attributes: In a command prompt window, the basic attributes used for editing a group of selected files or folders using attrib tool are

  • R- Assigns “Read-Only” attribute to prevent software programs from saving changes to a file.
  • H- Assigns “Hidden” attribute to prevent the view of a file under normal conditions.
  • A- “Archive” attribute allows the backup programs to know what files to back up.
  • S- This changes the selected files to “System” attribute so that it is exclusively used by the operating system

Syntax:

attrib [{+r|-r}] [{+a|-a}] [{+s|-s}] [{+h|-h}] [[Drive:][Path] FileName] [/s[/d]]

Or simply

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

 Parameters:

  • +r/-r sets or clears read-only file attribute
  • +a/-a sets or clears archive file attribute
  • +s/-s sets or clears system file attribute
  • +h/-h sets or clears hidden file attribute

When used without parameters, all files in the current directory are displayed.

[Drive:][Path] File Name: It is used to specify the location and name of the directory or a file, also, to display or change attributes for the desired set of files.

Wildcard characters such as, ? and * can be used in the Filename parameter to display or change the attributes for a group of files.

/s : Is used to search for a file in the specified path in the current directory including sub-directories.

/d :Specifies the application of attrib and any command-line options to directories.

For guidance or help in the command prompt,/?can be used.

Example for Read-Only attrib

To Open a command prompt window go to START menu and type CMD. Make sure that you enter the command prompt window as an admin and in order to do that right click on CMD and select “run as administrator” option.

Now, in this example let’s see how to assign Read-Only option to a particular file.In this scenario we are using a text file, Sample.txt.

Command: attrib +r C: \Sample\Sample.txt

atrrib read only example

 

Later, when anyone tries to make changes to Sample.txt it can’t be done hence protecting our file from unauthentic sources.

attrib read only example save file

 

In order to remove the Right-only attribute and to further edit your file use the following command.

Command:          attrib -r C: \Sample\Sample.txt

Example to hide your file

In order to maintain secrecy for your files Hide attrib is of the best use. It can be applied to a single file or folder and even a directory. In this particular example, we are hiding the Sample.txt file.

Command:          attrib +hC: \Sample\Sample.txt

attrib hide sample

By using the command you can see that the file is invisible. And to unhide the same use the following command.

Command:          attrib –h C: \Sample\Sample.txt

 

attrib example 3

Example to Archive your file

To maintain a backup for your file the best way is to archive it. The command used to prepare your file for archiving is

attrib example to archive file

 

Command:          attrib +a C: \Sample\Sample.txt

With this basic feed hope you are all set to play with your files and folders.