Win OS – Dos Command – Dir – Filtering

Background

In Microsoft’s Win OS, we use the dir ( directory ) command to list files and folders on the file system.

 

ls

Linux has its ls command.  We have dir.

Interesting enough, in Linux, everything is a file.

As such simply saying ls, that is list, is very short cut.

While being fully comprehensive at the same time.

 

dir

Let us review some of the options that are availed via the dir command.

Help

Help!

Let us get help.

Syntax


help dos

Output

Image

Option

Option Description Sub Option Example
Path The path or file to target c:\tmp
/A Filters on specific attributes D Directories
R  Read-only files
H  Hidden files
A  Files ready for archiving
S  System Files
L  Reparse Points
O Offline files
–   Prefix meaning not
/AD-
/b Bare /b
/O Sort /N Name
/S Size
/E Extension
/D Datetime
/- Reverse Order
/N
/Q Owner of the file /Q
/S Subdirectories /S

 

Sample

Filter

Directories Only ( /AD )

Objective

List folders only.

Syntax

dir /A:D

Sample

dir /A:D /s /b

Output
Image

 

Files Only ( /A-D )

Objective

List folders only.

Syntax

dir /A:-D

Sample

dir /A:-D /s /b

Output
Image

 

Bare ( /b )

Objective

Format listing in bare.

Skip folder names and summary.

Syntax

dir /b

Sample ( Files Only – Without bare )

dir /A:-D /s

Output
Image

 

Sample ( Files Only with Bare [ – /b ] )

dir /A:-D /s /b

Output
Image

 

Include Folder or File Owner ( /Q )

Objective

Include File Owner

Syntax

dir /Q

Sample

dir /Q

Output
Image

 

Explanation
  1. File Owner ( /Q )
    • The folder & File Owner is include
  2. Bare ( /b )
    • If bare ( /b) is requested, the /Q ( owner request ) is not met

 

Include Folders and Files in Sub-Directories ( /S )

Objective

Include Folders and Files in sub-directory.

Syntax

dir /S

Sample – Do Not Include Subdirectory

dir /A:-D /b

Output
Image

 

Sample – Include Subdirectory ( /s )

dir /A:-D /b /s

Output
Image

 

Explanation
  1. Sub-Directories ( /s )
    • Current Directory Only – No /s
      • Only include files in the current directory
    • Include Files in Sub-directories ( /s )
      • In this case, include the following files
        • family\Didi_01.txt

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s