ls

From RaySoft

ls is a command to list files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification.[1]

Documentation

Syntax

ls [PARAMETER ...] [FILE/DIRECTORY ...]

Parameters

General
The following parameters can be used with all version of ls:
NOTE:
BSD version only supports the short form (e.g. -a) of these parameters!
-1
List one file per line.
-a, --all
Do not ignore entries starting with .
-A, --almost-all
Like -a but do not list implied . and ..
--color[=WHEN]
Colorize the output. WHEN defaults to always or can be never or auto.
-F, --classify
Append indicator (one of */=>@|) to entries:
  • * for executables
  • / for directories
  • = for sockets
  • > for doors
  • @ for links
  • | for fifos
-h, --human-readable
Print with -l sizes in human readable format (e.g. 1K, 234M, 2G).
-i, --inode
Print the index number of each file.
-l
Use a long listing format.
-r, --reverse
Reverse order while sorting.
-R, --recursive
List subdirectories recursively.
-s, --size
Print size of each file, in blocks.
-S
Sort by file size.
-t
Sort by modification time.
GNU
The following parameters can be used with the GNU version of ls:
--time-style=STYLE
With -l, show times using style STYLE: full-iso, long-iso, iso, locale, +FORMAT. FORMAT is interpreted like date.
-X
Sort alphabetically by entry extension.
-Z, --context
Print any SELinux security context of each file.
BSD
The following parameters can be used with the BSD version of ls:
-D FORMAT
When printing in the long (-l) format, use FORMAT to format the date and time output. The argument format is a string used by strftime.
-G
Enable colorized output.

Examples

List all subdirectories and files of a directory
ls -laFh
List only subdirectories of a directory
ls -la | grep '^d'
Define aliases for directory listing
if type -P 'eza' >'/dev/null' 2>&1; then              # eza
  alias ls="eza --classify --time-style='long-iso'"
  alias ll='ls --git --group --header --long'
  alias l='ll --all --all'
else
  if ls --context >'/dev/null' 2>&1; then             # GNU ls version
    alias ls="ls --classify --color --time-style='long-iso'"

    if type -P 'dircolors' >'/dev/null' 2>&1; then
      eval "$(dircolors -b)"
    fi
  else                                                # other ls versions
    alias ls="ls -D '%F %T' -F -G"
  fi

  alias ll='ls -h -l'
  alias l='ll -a'
fi

alias lr='l -R'
alias lt="l -r -s 'time'"

References