cmd dir Command
The dir
command in Windows Command Prompt (cmd) is used to display a list of files and directories within a specified directory. It provides various options for filtering and formatting the output.
Basic Syntax
Key Components
- drive: The drive you want to list (e.g.,
C:
). - path: The directory path you want to list (e.g.,
C:\Users
). - filename: A specific file name or wildcard to filter results (e.g.,
*.txt
). - /options: Additional flags to modify the output.
Example Usages
1. List All Files and Directories in the Current Directory
Sample Output:
Explanation:
- The output shows the volume name, serial number, and directory listing with:
- Date and time of last modification.
<DIR>
for directories.- File sizes for regular files.
- Summary of total files, directories, and free space.
2. List Files in a Specific Directory
Sample Output:
Explanation:
- This shows the contents of the
Documents
directory, including file sizes and modification dates.
3. List All Files Recursively
Sample Output:
Explanation:
- The
/s
option lists all files and directories within the specified directory and its subdirectories.
4. List Only Directories
Sample Output:
Explanation:
- This lists only the directories in the current directory, omitting files.
5. List Files with Detailed Information
Sample Output:
Explanation:
- The
/w
option displays files and directories in a wide format, showing only names without additional details.
Common Options
/p
: Pauses after each screen of output./a
: Displays files with specified attributes (e.g., hidden)./o
: Sorts output (e.g., by name, size, or date)./b
: Displays filenames only (bare format)./q
: Displays the owner of each file.
Summary
The dir
command is essential for navigating and managing files and directories in the Windows Command Prompt. It provides a variety of options to customize the output, making it a powerful tool for file system operations.