dir

file managementLinux/Unix
The dir command is one of the most frequently used commands in Linux/Unix-like operating systems. dir List directory contents, similar to the ls command

Quick Reference

Command Name:

dir

Category:

file management

Platform:

Linux/Unix

Basic Usage:

dir [options] [arguments]

Common Use Cases

  • 1

    Directory listing

    List files and directories in the current or specified directory

  • 2

    File information

    Display detailed file attributes including permissions and size

  • 3

    System navigation

    Explore the filesystem structure to locate files

  • 4

    File management

    Identify files for operations like copying, moving, or deletion

Syntax

dir [OPTION]... [FILE]...

Options

Option Description
-a, --all Do not ignore entries starting with .
-l Use a long listing format
-h, --human-readable Print sizes in human readable format
-R, --recursive List subdirectories recursively
-S Sort by file size, largest first
-t Sort by modification time, newest first
--color[=WHEN] Colorize the output; WHEN can be 'always', 'auto', or 'never'
-1 List one file per line

Examples

How to Use These Examples

The examples below show common ways to use the dir command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

# Basic Examples Basic
dir
List files in the current directory.
dir -l
List files in long format with details.
dir -a
List all files including hidden ones. # Advanced Examples Advanced dir -lah Detailed list with human-readable sizes. dir --color=auto Display files with color highlighting. dir -S Sort files by size. dir -t Sort files by modification time. dir -R List subdirectories recursively.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Dir Command Overview: The dir command is essentially the same as the ls command in Linux/Unix systems. It lists information about files and directories. The dir command is included in GNU coreutils for compatibility with MS-DOS and Windows, where dir is the traditional command for listing directory contents. Functionality: By default, dir lists the files and directories in the current working directory, excluding hidden files (those starting with a dot). Various options allow you to modify the output format, sorting order, and which files are displayed. Common Usage: - List files in the current directory - View file details such as permissions, size, and modification date - See hidden files - Sort files by various criteria (size, date, etc.) - Display file sizes in human-readable format Difference from ls: While functionally equivalent to ls, the dir command is provided primarily for compatibility and familiarity for users transitioning from DOS or Windows systems. In most Linux/Unix environments, ls is the more commonly used command. Dir Output Coloring: When used with the --color option, dir can display different file types in different colors, making it easier to distinguish between regular files, directories, symlinks, etc. Exit Status: - 0: Success - Non-zero: An error occurred

Tips & Tricks

1

Use the -a option to show all files, including hidden ones

2

Use the -l option for a detailed listing with permissions and sizes

3

Use the -h option to display file sizes in human-readable format

4

Use the --color option to colorize the output by file type

5

Use the -R option to list subdirectories recursively

Common Use Cases

Directory listing

List files and directories in the current or specified directory

File information

Display detailed file attributes including permissions and size

System navigation

Explore the filesystem structure to locate files

File management

Identify files for operations like copying, moving, or deletion

Shell scripting

Programmatically obtain directory contents in scripts

Related Commands

These commands are frequently used alongside dir or serve similar purposes:

Use Cases

1

Directory listing

List files and directories in the current or specified directory

2

File information

Display detailed file attributes including permissions and size

3

System navigation

Explore the filesystem structure to locate files

4

File management

Identify files for operations like copying, moving, or deletion

5

Shell scripting

Programmatically obtain directory contents in scripts

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the dir command works in different scenarios.

$ dir
View All Commands