Change File Attributes Using Command Line

Here is how you can Change a File Attribute in Windows Using Command Line

A file system is a core part of every operating system today. While most modern file systems come equipped with basic features like copying or moving files, storing file sizes, supporting mounting drives, etc. there are still some fundamental differences in the functioning of each file system.

In Windows, each file has its own set of properties and attributes that store information about that particular file. From the file’s name to the file type (inferred from the file’s extension) to the size of the file and much more is stored in the file’s properties section that can tell you a lot about the file. There are also time tags like Creation Date and Modification Date which can tell you when the file was created and when it was last modified.

However, if you want to share a file with someone else and don’t want to give them this information along the file, there are several ways you can do that. Recently, we covered a guide on how you can access a file’s detailed properties and even add, change, or remove them.

Change or Remove a File’s Properties in Windows

In this guide, we will change a file’s attributes like read-only, hidden etc using the Windows Command Line, which is a much more appealing option for power users. Not only is it much quicker and can be done using just the keyboard, but it can also be accomplished using batch scripting. Here is how you can achieve it,

Change a File’s Property using the Command Prompt

We will be using the ATTRIB command. According to its documentation, it Sets or displays the read-only, archive, system, and hidden attributes of a file or directory.

Here is the syntax for this command,

ATTRIB [+ R|-R] [+A|-A] [+ H|-H] [+ S|-S] [d:][path]filename [/S]

Here are the different parameters you can use with it and their definitions,

  • +R – Use the +R option to make a file read-only.
  • -R – Use the -R option to change the file protection attribute back to normal (so it can be read, changed, or deleted).
  • +A – Use the +A option to set the ARCHIVE attribute of a file. W
  • -A – Use the -A option to turn off the ARCHIVE attribute.
  • +H – Use the +H option to set the HIDDEN attribute of a file so that it will not appear in a directory listing.
  • -H – Use the -H option to turn off the HIDDEN attribute.
  • +S – Use the +S option to set the SYSTEM attribute of a file. When the +S option is used, this flags the file as a command file used only by DOS. The file will not appear in a directory listing. This attribute is generally reserved for programmers.
  • -S – Use the -S option to turn off the SYSTEM attribute.
  • /S – Use the /S switch to set attributes on subdirectories found within the specified path.
  • path – he path where the file is placed
  • filename – The name of the file


ATTRIB +R myfile.txt