ATTRIB

From Wikipedia, the free encyclopedia
  (Redirected from Attrib)
Jump to: navigation, search

attrib is a command, in 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 of software programs 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[edit]

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

Particularities[edit]

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, for example

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[edit]

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.

Example[edit]

C:\DOS>attrib +S +H example.jpg

See also[edit]

References[edit]

  1. ^ Yabumoto, Kan (2000-01-17). "XXCOPY Technical Bulletin #06". Archived from the original on 13 July 2007. Retrieved 2007-08-02. 
  2. ^ "DOS Attrib". Encyclopedia. PC Magazine. Retrieved 2007-08-02. 

External links[edit]