Command Dir, Characteristics and Mode of Use

The Command line System in Windows operating system is an application used to execute specific commands. CMD, as it is also known, interprets commands on OS / 2 and Window NT-based systems. This application it is not part of the operating system nor does it influence in any way its load.

All the actions that are carried out with the CMD can be carried out from any interface. However, CMD can simplify the execution of some tasks. The variety of commands to execute with the CMD is quite extensive. In this article we will explain a specific command: the dir command.

To execute this command, as for any other, you must first open the CMD. To perform this action you can search for the start menu and write CMD. The menu will automatically show you the classic command line symbol with the name Command Prompt, all you have to do is click on it to execute it.

On the other hand, you can also access the CMD through the Windows Run window. To do this, press the Windows key and simultaneously. In the displayed window you type cmd and press Enter or click on the accept button.

Using the dir command

The dir command is used to list the files and subdirectories that are stored in a specific directory. Additionally, this command also displays the subdirectories within this same folder. To use it on a specific directory or folder, it is necessary to position the CMD cursor in that directory.

Either you can run the CMD from the directory in question, or through other commands “direct” the pointer to that specific directory. If the command dir is used without specifying any parameters, it will be displayed in the CMD lthe label and the volume serial number on the disk in question in the first two lines.

You will then see a list with the directories and files at this position on the disk. This includes the name and the date the file was last modified. If the label appears in front of a file

, means that this name is a subdirectory and not a file. In the case of files, with this command we will also see the size and extension of each one of them.

Using the dir command.

The last lines of the command output show the number of files and subdirectories in this directory. In addition, it shows the total size that all files occupy and the total free space on the disk.

How to use the dir command

To use the dir command you can position the root directory of the cmd in the folder on which you want to execute the command. This can be done using the cd command. Once we are in the desired directory we proceed with the command adding as many parameters as information we want to know about the directory. Another variant is to specify the directory on which we want to execute the command as a parameter of the command. The general syntax of the command is:

dir [<drive>:][<path>][<filename>] [...] [/p] [/q] [/w] [/d] [/a[[:]<attributes>]][/o[[:]<sortorder>]] [/t[[:]<timefield>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4] [/r]

Command attributes

Next, we will explain what each of the aforementioned attributes means and what it is for. It is valid to clarify that to execute the command it is not necessary to include all the attributes.

Parameter Description
[<drive>:][<path>] In this case the label “drive“Refers to the volume of disks and”path”To the directory where you want to run the command.
[<filename>] This parameter is used in case you want to execute the command for a specific file. It will only show information for that file.
/ p It is used to show, when the directory has many files, a part of the list in a first screen of the CMD. To see the following screens, press any key.
/ q This shows the information about the user who is owner of each file.
/ w It is used for show the list of files in width. That is, up to five files are displayed on each line of the output.
/ d This parameter is equal to / w, ordering the files alphabetically.
/to[[:] <attributes> ] In this case, the dir command will show files and subdirectories that meet the specified attributes . If not used, all files are displayed except system and hidden ones. If you use only / a without attributes, all files and subdirectories will be displayed including hidden and system files. The attributes to use can be:
d to show only directories.
h for hidden files.
s shows only system files.
l shows files with resume points.
r it will show read-only files.
to files that are ready to archive.
i files without content that have been indexed.
Any combination of these parameters can be used. If you are using more than one, you should not separate them by spaces. You can also use negation of parameters with the symbol – before it. That is, if you don’t want read-only files to be displayed, type –r and that’s it.

Other parameters associated with the dir command

We continue with the list of parameters for the dir command.

Parameters Description
/or[[:] <sortorder> ] This parameter is used to sort the displayed output on the console. To use it, you must replace “sortorder” with any of the following options:
n sorts the output alphabetically. e sorts alphabetically, but starting from the file extension.
g group directories are listed first.
s sort by size in ascending order d sort by date, oldest file first.
I could use any of the options described above to reverse the sort order with the symbol – ahead of option. If you are going to use several options, do not separate them by spaces. If the option is not specified, the / o parameter sorts the subdirectories alphabetically first, and the files after that also alphabetically.
/ t[[:] <timefield> ] In this case it is specified what to show in the time field of the output and how it will be ordered according to this field. Possible options are:
c by date of creation of the files.
to by the date of; last access to files.
w for the last time the file was written to.
/ s This parameter shows the number of times a file appears specified in the directory and in all subdirectories.
/ b Only the list of files and directories without including any additional information. This parameter does not allow the use of the / w parameter.
/ l Files and files not selected are displayed in lower case.
/ n Displays the list of files with the names on the right of the screen.
/4 The years of dates with four digits.
/? Displays help, for the dir command, from the command prompt

Other options for the command.

If you want to use multiple file names, separate them with a space, semicolon, or comma. In addition, you can use the cspecial characters “*” or “?” to replace one or more characters in file names. The * character can replace any string of characters. In this way, * .exe will refer to all files with an .exe extension. The character “?” refers to a single generic character. In this way, if we write “Ba? .Exe” we would be referring to all the files that start with ba, have some other character, and extension .exe.


Leave a Reply

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