how to use dir command with its examples

The dir command is used to list the directory, and with its multipe options we can get many details of a directory. This comes from “coreutils” package. If used efficiently this can be a very useful utility which can come handy for any linux administrator or linux enthusiast.

Examples:

1. To list all the directories

$ dir -a
$ dir –all 

2. To skip listing implied directory contents

$ dir -A

3. To list the author of the each file

$ dir –author

4. To print octal escapes for nongraphic characters

$ dir -b
$ dir –escapes 

5. To list the output using specified block size

$ dir –block-size=1024
$ dir -k=1024 

6. To skip listing entries ending with ~

$ dir -B
$ dir –ignore-backups

7. To list the contents with last modification time

$ dir -c

8. To list the entries by column

$ dir -C

9. To print the output in color

$ dir –color

10. To list only the directory entries

$ dir -d
$ dir –directory 

11. To not to sort the output

$ dir -f

12. To list the directories with specified format

$ dir -x (across)
$ dir -m (Commas)
$ dir -x (Horizontal)
$ dir -l (Long)
$ dir -1 (Single-column)
$ dir -l (Vebose)

$ dir -c (Vertical)

13. To list the directories with specifying the full time

$ dir –full-time

14. To skip listing owner with long list

$ dir -g

15. To group directories before files

$ dir –group-directories-first

16. Do not list entries with specified pattern

$ dir –hide=ana*
$ dir -I=ana*
$ dir –ignore=ana* 

17. To print the inode number of each file

$ dir -i
$ dir –inode

18. To list the entries with comma seperated list

$ dir -m

19. To list the entries with owner and group IDs

$ dir -n
$ dir –numeric-uid-gid 

20. To print the raw entry names

$ dir -N
$ dir –literal 

21. To list the entries without group info

$ dir -o

22. To append the indicators to the directories

$ dir -p /

23. To enclose the entry names in double quotes

$ dir -Q
$ dir –quote-name

To use quoting style

$ dir –quoting-style=slash
$ dir –quoting-style=literal
$ dir –quoting-style=locale
$ dir –quoting-style=shell-always
$ dir –quoting-style=c
$ dir –quoting-style=escape


literal, locale, shell, shell-always, c, escape

To reverse order while sorting

$ dir -r
$ dir –reverse 

To list sub directories recursively

$ dir -R
$ dir –recursive 

To print the allocated size of each file in blocks

$ dir -s
$ dir –size

To sort by file size

$ dir -S

To sort by work instead of name

$ dir –sort=WORD

none -U, extension -X, size -S, time -t, version -v

To list the files specified times (used with -l option)

$ dir –time=WORD -l

atime -u, access -u, use -u, ctime -c, or status -c; use specified time as sort key if –sort=time

To list the time with style (used with -l option)

$ dir –time-style=STYLE

full-iso, long-iso, iso, locale, +FORMAT.

To sort entries by modification time

$ dir -t

To list entries with specifying the tab size

$ dir –tabsize=8

To list entries in sorted order

$ dir -ult
$ dir -ul

To not to sort the entries

$ dir -U

To list entries with natural sort

$ dir -v

To list entries by line instead of columns

$ dir -x

To sort alphabatically

$ di -X

To list one file per line

$ dir -1

To display the security context

$ dir -Z

To display only security context and file name

$ dir –scontext

To display security context with long list

$ dir –lcontext

Leave a Reply

Your email address will not be published. Required fields are marked *