dir command in Linux is used to list the contents of a directory.
How is dir command different from ls?
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.
dir [OPTION] [FILE]
Useful options for dir command
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.
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.
3. -l –author option: Displays author of all the files. -l is required to display the contents in the form of a list.
dir -l --author
4. -B or –ignore-backups option: Ignores listing of backed up files. These files end with a `~`.
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).
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.
7. –file-type option: It is same as -F option, except that it does not append `*` to the executables.
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.
9. –hide=PATTERN or –ignore=PATTERN option: It ignores files described by shell PATTERN while listing the contents of a directory.
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.
11. -r, –reverse option: List files in reverse order while sorting.
12.-R, –recursive option: List subdirectories recursively.
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.
14. –help option: Display the help options and exit.
15. –version option: Outputs version information and exit.
- apt-get command in Linux with Examples
- until command in Linux with Examples
- bc command in Linux with examples
- last command in Linux with Examples
- top command in Linux with Examples
- look command in Linux with Examples
- arp command in Linux with examples
- tar command in Linux with examples
- cc command in Linux with Examples
- cvs command in Linux with Examples
- env command in Linux with Examples
- for command in Linux with Examples
- apt command in linux with examples
- col command in Linux with Examples
- rm command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.