How To Navigate, List Files and Directories In Windows Command Line With Dir? – POFTUT

How To Navigate, List Files and Directories In Windows Command Line With Dir?


Windows operating system provides command line tool named MS-DOS. This command line have different tools and capabilities for daily operations. We will look some simple steps about usage like navigation, list files and directories etc. We will mainly use dir command for this tutorial.

Help

Help information about dir command can be listed like below.

$ dir /?
Help
Help

Change Drive

Windows operating systems generally uses drive names for different partitions or disks. Most common usage of drive is splitting disk into two part and setting their name as C: and D: . If we have a CD-ROM we will also have a drive named E: . Changin the command prompt path between these drives can be done by issuing drive names into command line.

In this example we will change drive to D: with the same command.

$ D:

Or change drive to C: back again with command C:

$ C:

Navigate Upper Directory

Windows file system NTFS uses hierarchical structure for storing directories and files. In order to access upper directories and files we need to change the command line path with cd .. command to the upper directory.

$ cd ..
Navigate Upper Directory
Navigate Upper Directory

Navigate Selected Directory

Another mostly used navigation is changing command prompt directory into a child directory. We will use cd command with the directory name where we want to navigate. In this example we will navigate into directory named Users .

$ cd Users
Navigate Selected Directory
Navigate Selected Directory

List Files and Folders

Current working directory files, folders and folders can be listed with the dir command. We will do not provide any parameter.

$ dir
List Files and Folders
List Files and Folders

This command listed all files and directories with their date time and type information.

LEARN MORE  How To Backup Linux File System?

List Only Directories

In previous command we have listed all files, folders and directories but how can we only list directories. We will provide directory attribute with /A:D option.

$ dir /A:D
List Only Directories
List Only Directories

List Only Files

Another use case for dir command is listing only files. We will list only files with /A:-D option like below. This option actually negates so this will list non directories which is equal to files.

$ dir /A:-D
List Only Files
List Only Files

List Only Hidden Files

Hidden files are designed to be used by operating system. Users do not need these files to navigate, operate. This files generally holds cache or temporary values. We will use /A:H for list hidden files.

$ dir /A:H
List Only Hidden Files
List Only Hidden Files

The hidden files listing output provides information like date time and files type like DIR and JUNCTION

Sort By Name While Listing

Sorting is very useful feature while looking specific directories and files. Files, folders and directories can be sorted with /O:N option like below.

$ dir /O:N
Sort By Name While Listing
Sort By Name While Listing

Sort By Name While Listing In Reverse Order

We can list files, folders and directories alphabetically in reverse order. This start from z to sort. We will use /O:-N

$ dir /O:-N
Sort By Name While Listing In Reverse Order
Sort By Name While Listing In Reverse Order

Sort By Size While Listing From Smallest To Bigger

Files can be listed according to their sizes with the /O:S . This will start from smallest file and continue to bigger file.

$ dir /O:S
Sort By Size While Listing From Smallest To Bigger
Sort By Size While Listing From Smallest To Bigger

Sort By Size While Listing From Bigger To Smallest

We can reverse the default sorting according to size. We will sort from bigger to the smallest with the /O:-S

$ dir /O:-S
Sort By Size While Listing From Bigger To Smallest
Sort By Size While Listing From Bigger To Smallest

Sort By Date By Listing

Files, folders and directories can be listed according to their creation date with the /O:D .

$ dir /O:D
Sort By Date By Listing
Sort By Date By Listing

Display Owner Of The File

File, folders and directory owners can be listed and printed to the command line with /Q option.

$ dir /Q
Display Owner Of The File
Display Owner Of The File

In the output we will see the user and user domain or local system information.

Display Recursively

How can we list files, folders and folders deeper than current directory. We want to list all child file and folders and theirs childs up to end too. This is called recursive listing. We will use /S option to list all files and folder recursively.

$ dir /S
Display Recursively
Display Recursively

Display Creation Time

Creation time of the files, folder and directories can be listed with the /T:C option like below.

$ dir /T:C
Display Creation Time
Display Creation Time

Display Last Access Time

Last access time to the files, folder and directories can be /T:A option.

$ dir /T:A
Display Last Access Time
Display Last Access Time

Display Last Written Time

Las written time shows what is the last change time of the file or directory. We will use /T:W

$ dir /T:W
Display Last Written Time
Display Last Written Time

Leave a Comment