LinuxCommandLibrary

dir

List directory contents

TLDR

View documentation for the original command

$ tldr ls
copy

SYNOPSIS

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

PARAMETERS

-a, --all
    do not ignore entries starting with .

-A, --almost-all
    do not list implied . and ..

--author
    with -l, print author on same line

-b, --escape
    quote nongraphic chars as octal escapes

--block-size=SIZE
    scale sizes to SIZE blocks

-B, --ignore-backups
    ignore files matching *~

-c
    use time of last modification (default)

-C
    list entries by columns

--color[=WHEN]
    colorize output; WHEN=always|never|auto

-d, --directory
    list directory names themselves

-D, --dired
    output dired-style listings

--files0-from=F
    read input from F NUL-terminated

-f
    list in directory order, no sort

-F, --classify
    append file type indicator

--format=WORD
    WORD=across|vertical|long|single-column|two-per-line|long-long|columns|commas

--full-time
    print full timestamps

--group-directories-first
    group dirs before files

-h, --human-readable
    print human-readable sizes

--si
    like -h, but use powers of 1000

-H, --dereference-command-line-symlink-to-dir
    follow symlinks on command line

--hyperlink[=WHEN]
    hyperlink file names; WHEN=always|never|auto

-i, --inode
    print inode number

-I
    ignore pattern PATTERN

-l
    long listing format

-L, --dereference
    when showing file info, show where they point

-m
    separate with commas

-n
    numeric user/group IDs

-N, --literal
    print entry names without quotes

--numeric-uid-gid
    like -n; ignored if -l not used

-p
    append / to directory names

-q, --hide-control-chars
    print ? instead of nongraphic

--show-control-chars
    print raw control chars

-Q, --quote-name
    enclose in double quotes

--quoting-style=WORD
    style of quoting

-r, --reverse
    reverse sort order

-R, --recursive
    list subdirectories recursively

-s, --size
    print size in blocks

-S
    sort by file size

--sort=WORD
    sort by WORD (name|extension|size|time|version|none)

-t
    sort by modification time

-T, --tabsize=COLS
    assume tab chars size COLS

-u
    with -lt: sort by access time

--time=WORD
    time type: atime|access|use|ctime|status|change

--time-style=STYLE
    time style: full-iso|long-iso|iso|locale|+FORMAT

-v
    natural sort of version numbers

-w, --width=COLS
    screen width in columns

-x
    list by lines, row-first

-X
    sort by extension

-1
    list one file per line

--help
    display this help

--version
    output version information

DESCRIPTION

The dir command, part of GNU coreutils, displays directory contents in a multi-column format by default when output is to a terminal, making it ideal for quick visual scans. Unlike ls, which may use single-column output, dir optimizes for width, fitting as many names as possible per line.

It supports extensive customization via options shared with ls, including sorting, formatting, recursion, and colorization. Use -l for detailed listings showing permissions, owner, size, and timestamps; -h for human-readable sizes; or -R to recurse into subdirectories.

Dir ignores files starting with '.' by default (use -a to show them) and handles wildcards for selective listing. It's efficient for large directories due to columnar layout but can be verbose with many options. Output to files or pipes defaults to single-column for compatibility.

Common in scripts for formatted listings without specifying -C. On modern systems, ls often aliases include color, while dir requires --color=auto. Always respects umask and permissions; cannot list inaccessible files.

CAVEATS

Output may wrap poorly on narrow terminals; large directories slow without paging (| less). Cannot traverse permission-denied dirs with -R. Color output unreliable in non-terminals. Symbolic links shown as targets with -L. Ignores core dumps and backups by default in some locales.

EXAMPLES

dir /tmp
dir -l *.log
dir -lahR ~

EXIT STATUS

0: success
1: minor problems (e.g., missing files)
2: serious issues (permissions, invalid options)

HISTORY

Originated in GNU fileutils (1980s-1990s), merged into coreutils by 2000s. Developed by GNU Project for POSIX compliance with extensions; defaults evolved for usability (columnar from early versions). Maintained by coreutils team; current in coreutils 9.x.

SEE ALSO

ls(1), vdir(1), find(1), du(1), tree(1)

Copied to clipboard