dir command in Linux with examples - GeeksforGeeks

15 May, 2019
dir command in Linux is used to list the contents of a directory.
dir command differs from ls command in the format of listing contents that is in default listing options.By default, dir command lists the files and folders in columns, sorted vertically and special characters are represented by backslash escape sequences. But unlike ls, when the output is on terminal, it does not produce colored output as ls does.
SYNTAX:
 dir [OPTION] [FILE] 
1. -a or –all option: It displays all the hidden files(starting with `.`) along with two files denoted by `.` and `..` which signals for current and previous directory respectively.SYNTAX:
 dir -a 
EXAMPLE:
2. -A or –almost-all option: It is similar to -a option except that it does not display files that signals the current directory and previous directory.SYNTAX:
 dir -A 
EXAMPLE:
3. -l –author option: Displays author of all the files. -l is required to display the contents in the form of a list.SYNTAX:
 dir -l --author 
EXAMPLE:
4. -B or –ignore-backups option: Ignores listing of backed up files. These files end with a `~`.SYNTAX:
 dir -B 
5. –color option: (can be followed by =[TIME]).It is used to colorize the output. In the absence of time specification which can be auto, never or always, it colorizes the output always (default behavior).SYNTAX:
 dir --color 
EXAMPLE:
6. -F, –classify option: Append indicator (one of */=>@|) to the file names which classifies them into their type. The meanings of symbols are as follows:
A slash (`/`) indicates a directory.
An asterisk (`*`) indicates an executable.
An at sign (`@`) indicates a symbolic link.
A percent sign (`%`) indicates a whiteout.
An equal sign (`=`) indicates a socket.
A vertical bar (`|`) indicates a FIFO.
SYNTAX:
 dir -F 
EXAMPLE:
7. –file-type option: It is same as -F option, except that it does not append `*` to the executables.SYNTAX:
 dir --file-type 
EXAMPLE:
8. –format=WORD option: It formats the listing of entries. The WORD can take the following values: across, commas, horizontal, long, single-column, verbose, vertical. The same can be achieved by passing -x, -m, -x, -l, -1, -l, -C options to dir command for each of the respective values.SYNTAX:
 dir --format=WORD 
EXAMPLE 1:EXAMPLE 2:
9. –hide=PATTERN or –ignore=PATTERN option: It ignores files described by shell PATTERN while listing the contents of a directory.SYNTAX:
 dir --hide=PATTERN 
EXAMPLE:
10. -n, –numeric-uid-gid option: This option is similar to the long listing that is -l option except that it lists numeric user and group IDs.SYNTAX:
 dir -n 
11. -r, –reverse option: List files in reverse order while sorting.SYNTAX:
 dir -r 
EXAMPLE:
12.-R, –recursive option: List subdirectories recursively.SYNTAX:
 dir -R 
EXAMPLE:
13.–sort=PARAMETER: To list files in a sorted manner described by the PARAMETER. The PARAMETER can take the following values: none (-U), size (-S), time (-t), version (-v), extension (-X).Instead of passing –sort option, the flags indicated in the brackets can directly be passed as options to sort the listing.SYNTAX:
 dir --sort=PARAMETER 
EXAMPLE 1:EXAMPLE 2:
14. –help option: Display the help options and exit.SYNTAX:
 dir --help 
EXAMPLE:
15. –version option: Outputs version information and exit.SYNTAX:
 dir --version 
linux-command
Linux-directory-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Thread functions in C/C++
nohup Command in Linux with Examples
scp command in Linux with Examples
chown command in Linux with Examples
Array Basics in Shell Scripting | Set 1
mv command in Linux with examples
Basic Operators in Shell Scripting
SED command in Linux | Set 2
Docker - COPY Instruction
Named Pipe or FIFO with example C program