Which command is used to display all the files in your current directory and its?

Updated: 12/30/2021 by

Which command is used to display all the files in your current directory and its?

The dir command displays information about files and directories, and how much disk space is available. By default, it displays the name, size, and last modification time of every file in the current directory.

Availability

Dir is an internal command available in the command line of all Microsoft operating systems.

  • All Versions of MS-DOS
  • Windows 95
  • Windows 98
  • Windows ME
  • Windows NT
  • Windows 2000
  • Windows XP
  • Windows Vista
  • Windows 7
  • Windows 8
  • Windows 10
  • Windows 11

Description

The dir command displays a list of files and subdirectories in a directory. With the /S option, it recurses subdirectories and lists their contents as well.

Options listed below may be preset in the DIRCMD environment variable. To override preset options, prefix any switch with - (hyphen), for example, "/-W".

Syntax

The syntax of the dir command has evolved somewhat over time. Select your operating system to jump to the information that applies to your version.

  • Windows 11, 10, 8, 7, Vista, XP, and 2000 syntax.
  • Windows ME, 98, 95, 3.x, and MS-DOS syntax.

Windows 11, 10, 8, 7, Vista, XP, and 2000 syntax

DIR [Drive:][Path][FileName] [/A[[:]Attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]SortOrder]] [/P] [/Q] [/R] [/S] [/T[[:]TimeField]] [/W] [/X] [/4]
[Drive:][Path][FileName] Specifies the drive, directory, or files to list. Multiple filespecs are allowed, e.g., "*.txt *.exe".
/A:Attributes Displays only files with the specified file attributes. Attributes is several letters, each representing an attribute as shown below.

D : Directories.
R : Read-only files.
H : Hidden files.
A : Files marked ready for archiving.
S : System files.
I : Non-indexed files.
L : Reparse points.
- : Prefix meaning "not".

For example, the option "/A:R-A" would match only files whose attributes (/A:) are read-only (R) and not (-) ready to be archived (A).

/B Uses bare format (no heading information or summary, only the information itself).
/C Display the thousand separator in file sizes (e.g., a comma after every third digit), which is the default setting. Use /-C to disable the display of separator.
/D Same as wide (/W), but files are sorted by column, rather than by row.
/L Uses lowercase in the output.
/N "New long-list" format, which displays file names on the far right.
/O:SortOrder Sort the list of files by SortOrder, a series of letters representing sort criteria.

N : By name (alphabetic).
S : By size (smallest first).
E : By extension (alphabetic).
D : By date/time (oldest first).
G : Group directories first.
- : Prefix to reverse order.

For instance, an option of "/O:D" displays files oldest-to-newest, and "/O:-S" displays files biggest-to-smallest.

/P Pauses after each screenful of information.
/Q Display the owner of the file.
/R Display alternate data streams of the file.
/S Displays files recursively, traversing any subdirectories.
/T TimeField Specify the time field displayed and used for sorting. TimeField may be any of the following letters.

C : Creation time.
A : Last access time.
W : Last write time.

For instance, when you use the option "/T:C," the time listed is when the file was created.

/W Uses wide list format, displaying file/folder names only, with multiple names on every line.
/X Displays the short names generated for non-8dot3 file names. The format is that of /N ("new long-list" format, see above), with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.
/4 Display years with four digits, e.g., 2018 instead of 18.

Windows ME, 98, 95, 3.x, and MS-DOS syntax

DIR [Drive:][Path][FileName] [/P] [/W] [/A[[:]attributes]] [/O[[:]sortorder]] [/S] [/B] [/L] [/V]
[Drive:][Path][FileName] Specifies drive, directory, or files to list. Multiple filespecs are allowed, e.g., "*.txt *.exe".
/P Pauses after each screenful of information.
/W Uses wide list format.
/A[:Attributes] List only files with the specified file attributes. Attributes is several letters indicating:

D : Directories.
R : Read-only files.
H : Hidden files.
A : Files ready for archiving.
S : System files.
- : Prefix meaning "not".

/O[:SortOrder] List files in sorted order, indicated by SortOrder.

N : By name (alphabetic).
S : By size (smallest first).
E : By extension (alphabetic).
D : By date and time (earliest first).
G : Group directories first.
- : Prefix to reverse order.
A : By last access date (earliest first).

/S List files and directories recursively, traversing subdirectories.
/B Uses bare format (no heading information or summary).
/L Uses lowercase.
/V Verbose mode. Display extra information.

Examples

dir

Lists all files and directories in the current directory.

dir *.exe

Lists any file whose name has the file extension ".exe".

Note

Because of how the wildcard matching works, it's also shows files with a file extension with four or more characters (e.g., .exec).

dir *.txt *.doc

List any files whose name has the file extension ".txt" or ".doc".

dir /a:d

Lists only directories.

dir /a:r

List only files with the read-only attribute.

dir /s

Recursively lists files and directories in the directory, and in any subdirectories. For instance, if your current directory is the root directory "C:\>," this command lists every file and directory on the C: drive.

dir /p

Pause after each screenful of output. Use this option if the information is scrolling past the screen before you can read it. You are prompted to press any key before listing continues past the current screen.

dir /w

Lists multiple file names on every line, producing "wide" output, which displays more file names at once. However, other information such as file size is omitted.

dir /s /w /p

Recursively lists all files and directories in the current directory and any subdirectories, in wide format, pausing after each screen of output.

dir /s /w /p "C:\Program Files"

Same as the above command, but lists everything in C:\Program Files, instead of the current directory. Because the directory name contains a space, it is enclosed in double-quotes, to prevent it from being interpreted is as two separate options.

dir /o:n

Lists files and directories in the current directory in alphabetical order. This example is the same as only running dir because files and directories are listed in alphabetical order by default.

dir /o:-n

Lists files in reverse alphabetical order.

dir /s /q /a:sh /p C:\Windows

Lists any files and directories in C:\Windows, and any of its subdirectories (/s), which have both the "hidden" and "system" file attributes (/a:sh). Also, lists the owner of the file (/q), and pauses after each screen of output (/p).

dir \ /s | find "i" | more

The above command uses vertical bars to pipe the output from dir to the command find, and then to the command more. The result is a list of all files and directories in the root directory of the current drive (\), with extra information. Namely, find also displays the number of files in each directory, and the amount of space occupied by each.

dir > myfile.txt

Runs the dir command, but redirects the output to the file myfile.txt, instead of displaying it on the screen. Here, the dir command has no options, but redirection works with any command you specify, so the following command also works.

dir /s /a:hs /q C:\Windows > myfile.txt

To view the contents of the file, you can use the type command.

type myfile.txt

If the file is very long, you can pipe type to more, so it pauses after each screen.

type myfile.txt | more

Which command is used to display all the files including hidden files in your current and its subdirectories?

The ls command lists the contents of the current directory. The –a switch lists all files – including hidden files.

Which command is used to list all the files in your current directory as well as in subdirectories?

The ls (list) command is used to display the names of the files and subdirectories in the current directory.

Which command should you use to list all files of your current directory in Linux?

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

Which command should you use to display the current path of your current directory?

Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory). All directories are separated by a slash (/).