dir
List directory contents
TLDR
List all files, including hidden files
List files including their author (-l is required)
List files excluding those that match a specified blob pattern
List subdirectories recursively
Display help
SYNOPSIS
dir [OPTION]... [FILE]...
PARAMETERS
-a, --all
Do not ignore entries starting with '.'
-A, --almost-all
Do not list implied '.' and '..'
-l
Use a long listing format, showing permissions, owner, size, and date. This overrides dir's default columnar output.
-R, --recursive
List subdirectories recursively.
-F, --classify
Append indicator (one of */=>@|) to entries.
-h, --human-readable
With -l, print human readable sizes (e.g., 1K 234M 2G).
-S
Sort by file size, largest first.
-t
Sort by modification time, newest first.
--color[=WHEN]
Colorize the output. WHEN can be 'always' (default), 'never', or 'auto'.
-1, --format=single-column
List one file per line, effectively disabling dir's default multi-column output.
-d, --directory
List directories themselves, not their contents.
DESCRIPTION
The dir command in Linux is a utility used to list the contents of directories. It is essentially a variant of the ls command, often implemented as a hard link to ls with specific default options enabled. Its primary purpose is to provide an output format similar to the dir command found in DOS and Windows operating systems, making it familiar to users migrating from those environments. By default, dir lists files and subdirectories in a multi-column, vertically sorted format, without showing additional details like permissions, ownership, or timestamps. This behavior is equivalent to running ls -C --format=vertical. This default output makes it suitable for a quick, concise overview of directory contents. While it shares virtually all capabilities with ls when additional options are provided, its distinctive default presentation caters specifically to users seeking a simple, uncluttered list of items within a directory.
CAVEATS
The dir command is primarily provided for compatibility with DOS/Windows users and for scripting where a specific columnar output is desired. For advanced file listing and detailed information, the ls command offers more flexibility and is generally the preferred tool in native Linux environments. Its behavior is often identical to ls -C --format=vertical, so understanding ls is key to fully utilizing dir.
DEFAULT BEHAVIOR
By default, dir behaves like ls -C --format=vertical. This means it lists files and directories in multiple columns, sorted vertically within columns, and does not show hidden files or detailed information (permissions, size, date, etc.).
RELATIONSHIP TO LS
In most Linux distributions, dir is either a hard link or an alias to the ls executable. This implies that any options valid for ls can generally be used with dir, though dir might have pre-set default options that are overridden by explicitly provided ls options. Therefore, while we list common options, any option documented for ls is generally applicable.
HISTORY
The dir command has been part of GNU Core Utilities for a long time, primarily as a convenience alias or hard link to the more powerful ls command. Its inclusion is largely to provide a familiar command interface for users accustomed to the dir command in MS-DOS and Windows operating systems, facilitating an easier transition to Linux. While ls is the native and more feature-rich command for listing directory contents in Unix-like systems, dir serves its purpose by offering a quick, columnar view of files by default.