Programming Field

Attrib - DOS/Command Prompt Reference

Displays or changes file attributes.

Syntax

attrib[.exe] [+R | -R] [+A | -A] [+S | -S] [+H | -H]
    [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U]
    [<file-name>] [/S [/D]] [/L]

Options

+R, -R, +A, -A, +S, -S, +H, -H, +O, -O, +I, -I, +X, -X, +P, -P, +U, -U

Sets or unsets attributes for corresponding characters. + will set the attribute, and - will unset the attribute.

CharacterDetails
RRead-only attribute. This attribute disables overwrites. Also this attribute disables deletion with Del command ([Windows NT series] unless using /F option).
AArchive attribute. Some backup applications will backup files that have this attribute.
SSystem file attribute. As system files, several accesses will be strictly controlled. For example, changing attributes for files with this attribute is blocked. Also, files with this attribute will not be displayed in Dir command or etc. without specific options. On Windows, files with this attribute will be displayed, but changing hidden file attribute will be blocked.
HHidden file attribute. Files with this attribute will not be displayed in Dir command or etc. without specific options. On Windows Explorer, files with this attribute will appear semi-transparent even if visible.
O[NTFS/ReFS file system] Offline attribute. Files with this attribute basically exist on a remote location, and files' contents may not be available immediately.
I[NTFS/ReFS file system] Not content indexed file attribute. even if indexing feature (to increase search speed for files) is enabled, contents of files with this attribute are excluded for indexing.
X[NTFS/ReFS file system] No scrub file attribute. This attribute is available only for files in ‘Storage Spaces’ or ReFS, and files with this attribute are excluded for integrity scanner (scrubber) operated in background.
P[Windows 10 1709 or later] [NTFS/ReFS file system] Pinned attribute. When sharing files using OneDrive, this attribute represents ‘always keep on this device’ (see below). When specifying this attribute to the directory, it is used as the default for files within its directory (not ‘pinning’ all files within its directory). This attribute works only for files/directories shared with OneDrive. ‘P’ and ‘U’ cannot be specified at the same time.
U[Windows 10 1709 or later] [NTFS/ReFS file system] Unpinned attribute. When sharing files using OneDrive, this attribute represents ‘increasing free spaces’ (see below). This attribute works only for files/directories shared with OneDrive.

If no ‘+’ and ‘-’ options are specified, Attrib displays file attributes for the target files/directories by using characters described in the above table.

In addition, the following characters will also be displayed when files have corresponding attributes.

CharacterDetails
V[ReFS file system] Integrity attribute. This attribute is used to let files work Copy on Write (COW; also known as Allocate on Write).
B[Windows 10 1709? or later] [NTFS file system?] (Unknown; corresponding to the attribute FILE_ATTRIBUTE_STRICTLY_SEQUENTIAL. In Attrib help this attribute is described as ‘SMR Blob attribute’.)

* Currently ‘V’ and ‘B’ cannot be used with ‘+’ and ‘-’ for changing these attributes. (as of Windows 11 22H2)

<file-name> Specifies a file name to change attributes. If omitted, Attrib performs the operation for all files in the current directory (displays attributes if no ‘+’ and ‘-’ are used, or changes attributes if either or both is used).
/S Performs the operation (changes attributes or displays attributes) for not only files in the current directory but also files in its subdirectories.
/D [Windows NT series/XP or later] Changes (or displays) attributes for not only files but also subdirectories themselves in the current directory. If /S is also specified, sub-subdirectories are included.
/L [Windows NT series/XP or later] If <file-name> refers to the symbolic link (junction point), changes (or displays) attributes for its link itself. If /L is not specified, attributes of the file or directory linked by its link will be changed (or displayed).

Details

Usage of Attrib

About Attrib

Attrib can be used to change file attributes such as ‘Read-only’, ‘Archive’, ‘System file’, ‘Hidden file’, and ‘Not content indexed file’ (NTFS file system or etc.). These attributes may affect behaviors on some commands, MS-DOS, and Windows. For example, ‘Hidden-file’ attribute files does not appear on Dir command and Windows Explorer (when ‘display hidden files’ setting is off).p>

[Windows NT series/XP or later] Attrib does not treat Access Control List (ACL) in NTFS file system or etc. To modify Access Control List, use Cacls command or Icalcs command.

* Attrib cannot be used to change ‘Compressed file’, ‘Encrypted file’, and ‘Temporary file’ attributes.

Attributes for OneDrive

[Windows 10 1709 or later] Attrib can be used to change ‘P’ (Pinned) and ‘U’ (Unpinned) attributes for OneDrive ‘Files On-Demand’ feature. These attributes represent as follows:

  • With ‘P’ attribute : ‘Always keep on this device’ status (the green circle with the white check mark in Explorer)
  • With ‘U’ attribute : ‘Free up space’ status (the blue cloud icon in Explorer)
  • Without ‘P’ and ‘U’ : ‘Locally available’ status (the white circle with the green check mark in Explorer)

* You cannot set both ‘P’ and ‘U’ at the same time.

‘U’ attribute represents that the file data is not downloaded, and when opening its file with online status, the data will be downloaded and ‘U’ attribute will be removed. Since the data of the file with ‘U’ attribute does not exist in local disk, its data cannot be searched with offline status, and reading the data will fail with offline status.

No ‘U’ attribute represents that the file data is downloaded (synchronized) and available locally. As described above, the data of the file with ‘U’ attribute will be downloaded when online, and ‘U’ attribute will be removed. Also, data of files without ‘U’ attribute is always synchronized when online.

‘P’ attribute represents ‘pinned’, in addition to file behavior without ‘U’ attribute (i.e. data is downloaded and available locally), that the data is always kept locally. This means that data of files without ‘P’ attribute may be removed as needed, and ‘U’ attribute may be added to the files (files themselves will not be removed). Therefore, if you want the data to be always available locally, it is better to add ‘P’ attribute to the files.

* The operation ‘data of files without P attribute may be removed as needed’ may be performed when the drive gets low space, but it is unconfirmed whether the operation will be actually performed. For more details, please see ‘Files on demand - difference in 'locally available' and 'always available' files - Microsoft Community Hub’ and etc.
* Even if the data is not read, the data will be downloaded just when ‘U’ attribute is removed.

Note that the above behavior occurs only when ‘Files On-Demand’ feature is enabled; otherwise ‘P’ and ‘U’ attributes are ignored (can be added but have no meanings), and files/folders are always synchronized when online.

Samples

Sample 1

attrib +R +H +S c:\command.com

Adds Read-only, Hidden file, and System file attributes to c:\command.com (these attributes are commonly added to most important files).

Sample 2

attrib -H -S c:\hoge.foo

Removes Hidden file and System file attributes from c:\hoge.foo . In MS-DOS/Command Prompt, operations for Hidden file and System file are rejected with ‘File does not exist’, so this is necessary when operating for those files.

Sample 3

attrib +A D:\MyDocs\*.* /S
attrib -A D:\MyDocs\*.bak /S
attrib -A D:\MyDocs\*.tmp /S
xcopy D:\MyDocs E:\Backup\MyDocs\ /E /M

Adds Archive attribute to all files in ‘D:\MyDocs’, and removes Archive attribute to all files with ‘bak’ and ‘tmp’ extensions. And more, uses Xcopy program to copy all files with Archive attribute to ‘E:\Backup\MyDocs’. Note that Xcopy /M option will remove Archive attribute from copy source files (Archive attribute of copy destination files is kept).

Sample 4

attrib -P +U P:\Data\Logs /S

[Windows 10 1709 or later] Marks ‘Unpinned’ for all files in ‘P:\Data\Logs’ and its subdirectories which shared with OneDrive. This is useful to save disk space when data is not necessary locally.

Sample 5

attrib +P -U P:\Data\Lists /S

[Windows 10 1709 or later] Contrary to the above, marks ‘Pinned’ for all files in ‘P:\Data\Lists’ and its subdirectories which shared with OneDrive. This is used to prevent downloaded data from being ‘Unpinned’ and unavailable, and to ensure that it is always available offline. For example, this is used by administrators to keep shared data available locally (not removed when the disk space is low) on multiple managed mobile PCs.

See also