CMD Attrib Command Help – Syntax and Tricks

0 Flares Filament.io 0 Flares ×

ATTRIB is a command in Microsoft Windows, DOS and OS/2 which allows the user to switch various characteristics or ‘attributes’ of a directory or file. ATTRIB command was first included in the third version of PC-DOS and the functionality was limited switching the read-only attributes. With more and more developments, MS-DOS version 3.3 featured the capability of recursive searching through directories and sub directories to display attributes of the files.

Using the ATTRIB command, one can change a file’s write or read attribute or set the archive attribute. When you use this command to specify a file as read-only, the file can be accessed but not edited or deleted. If a file has an attribute of -R, it can be written to or read from and if it has +R attribute, it can be only read from but not written to. The RESSTORE, XCOPY and BACKUP commands use the archive attribute. You can use the +A or -A options to back up selectively using BACKUP command or copy using XCOPY.

CMD

The syntax for CMD ATTRIB command is as follows:

 

ATTRIB [d:][path]filename [/s]

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

The key words / notations are:

–           : to clear an attribute OFF

 

+          : to turn an attribute ON

 

pathname : drive and/or filename

/S         :  to search the pathname inclusive of all subfolders

/D        : to process folders

Attributes:

R : read-only(1)

H: Hidden (2)

A: Archive (32)

S: System (4)

 

Extension of attributes:

E: encrypted

 

C: compressed

I: non content-context

 

L: symbolic link/ junction

N: normal

 

O: offline

P: sparse file

T: temporary

The numeric values can be used when changing attributes with VBS/WSH whereas if no attribute is specified attrib can return to original settings on its own.

Key points and tricks

Attrib

 
  • The hidden and system attributes take priority. If a file has both the hidden and system attributes already set, you can clear both of them only with a single ATTRIB command. For example:

ATTRIB -S -H RECORD.TXT

  • You can use the filename parameter with the wildcards (? And *) to display the attributes for a group of files. If a file contains System or Hidden attribute set you must clear the attribute before you alter anything else.
  • Attributes for a directory/folder can be displayed or changed. For a directory, you must explicitly specify the directory name without using any wildcards to work with directories.
  • To hide a directory C:\SECRET, type ATTRIB +H C:\SECRET. The command that would affect only the files and not the directories is: ATTRIB +H C:*.*
  • The file attributes can be read using the command:

fsutil usn readdata filename.ext

for example:

FILE_ATTRIBUTE_READONLY = 1

FILE_ATTRIBUTE_HIDDEN = 2

FILE_ATTRIBUTE_SYSTEM = 4

 

FILE_ATTRIBUTE_DIRECTORY = 16

 

 

So using these tricks and the syntax for CMD command you can manipulate the attributes of a file or a directory in order to set or display the read-only, the system and the archives.

 

 

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    0 Flares Twitter 0 Facebook 0 Google+ 0 StumbleUpon 0 LinkedIn 0 Filament.io 0 Flares ×