The Full Wiki

Attrib: Wikis


Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.


(Redirected to attrib article)

From Wikipedia, the free encyclopedia

attrib is a command, in MS-DOS, OS/2 and Microsoft Windows. The function of attrib is to set and remove file attributes (read-only, archive, system and hidden). These attributes are used by a wide variety software to protect and classify files.[1]

Many users regularly encounter the read-only attribute, which will prevent most software from allowing the user to overwrite or append to a file. Software can be designed to override this option, often after receiving confirmation from the user. The archive attribute is used by various backup and file copy programs as a hint as to whether a file needs to be backed up.[2] The hidden attribute makes affected files invisible in many programs, although a variety of software, especially software designed for listing, viewing, and searching files, allows hidden files to be made visible, often with a notation that they have been designated as hidden. The system attribute is used to designate certain operating system files and affects the operation of most software less than the other attributes.


Definition of attrib Command

There are four attributes in Windows files:

  • (r) Read-only file attribute
  • (a) Archive file attribute
  • (s) System file attribute
  • (h) Hidden file attribute

One or more of these attributes can be set [+x] or cleared [-x] in a single instance of the command for a specific file, file type, folder or and entire branch of the directory structure (a directory, including all sub-directories). There are three optional switches that can be applied at the end of the DOS command string, although not all switches are recognized for all versions of Windows. These switches are:

  • /S also apply changes to subdirectories of current directory
  • /D also apply changes to folder names (this only applies for Windows 2000 and Windows XP)
  • /L apply to symbolic link itself instead of the target of the symbolic link (introduced with Windows Vista and Windows Server 2008)

The general attrib command syntax is:

attrib [+r|-r] [+a|-a] [+h|-h] [+s|-s] [d:][path]filename [/s] [/d] [/l]

For example, to remove the read-only and hidden file attributes for all files in a directory tree:

attrib -r -h *.* /s /d

Note, the -s parameter will also remove the system attribute for files and should always be used with care and should not be used for genuine system files.



In certain versions, when both the s and h attributes are both set, they can only be removed at the same time. Therefore, to remove only one, both must first be removed, and then the desired attribute can be (re)set.

ie. C:> attrib -S -H *.*

The command will not clear the Read-Only flag from Hidden files and will report that the flag was not cleared on each file.

Differences between Windows versions

The "/D" switch (which recurses into sub-directories) was introduced with Windows XP and Windows Server 2003, and "/L" (which instructs attrib to work with the attributes of the symbolic link itself instead of the target of the symbolic link) was introduced with Windows Vista and Windows Server 2008.

Undocumented features

If a comma is typed directly after the command's name (for example, attrib, *.txt), all attributes will be removed from the targeted files (in this case, all .txt files in the folder). In most versions, if a target isn't specified, then all attributes will be removed from the folder currently being browsed in DOS.

Use in defragmentation

Copying files from read-only media such as a CD or DVD backup will preserve the read-only flag on the files. There is no need for this flag on your read/write drive. Read-only files will interfere with the effectiveness of defragmentation in two ways:

  1. Larger files may have been copied to your drive in fragments. These fragments will not be able to be reunited and will remain fragmented.
  2. Smaller files will not be able to be moved to the best location and may prevent the assembling of contiguous free space needed for large files.

Thus when you want to defragment your drive you need to clear the Read-Only flag on all files. From dos in the root directory issue the following command;

C:> attrib -R *.* /S /D

Hidden files will not be made read/write by this command. An example of a hidden file is the thumbnail index in picture directories. You will be notified of hidden files when running the above command. You may run this command to set the hidden files to read/write;

C:> attrib -H -R *.* /S /D

See also


  1. ^ Yabumoto, Kan (2000-01-17). "XXCOPY Technical Bulletin #06". Retrieved 2007-08-02.  
  2. ^ "DOS Attrib". Encyclopedia. PC Magazine.,2542,t=DOS+Attrib&i=41730,00.asp. Retrieved 2007-08-02.  

External links


Got something to say? Make a comment.
Your name
Your email address