Examples

  1. ls *
    ls
    ls -fd *

    These commands all mean the same thing: List all ordinary files and subdirectories within the current directory. They match the same files that the DOS command DIR *.* matches.

  2. ls *.*

    This command lists all ordinary files in the current directory that have an extension (that is, that have a dot in their file name). This is not the same as the ls * command nor is it the same as the DIR *.* command, since it won't list any files or directories whose name contains no dot.

  3. ls -Cn

    List all files in the current directory in multi-column format, sorted by name. This is the default behaviour for the ls command when stdout is the display (and when ls is entered with no flags or arguments).

  4. ls *.c

    List all files in the current directory that end in the .c suffix (or have the .c extension, in DOS's words).

  5. ls *.c *.h
    ls *.[ch]

    List all files in the current directory that end in either .c or .h. These commands show the same results. In the first command, notice that you can enter more than one file specification. In the second command, notice that the one Bourne shell pattern can replace the two simplistic DOS-sytle patterns.

  6. ls -Rd c:/
    ls -Rd c:\

    List all directories and subdirectories on drive C, starting at the root directory. This produces a tree listing of drive C.

    Both \ (backslash) and / (forward slash) characters are interpreted as path separators. When showing the matching directory entries, ls will use the last path separator (if any) that you entered on the command line.

    If you didn't enter a path separator on the command line, then ls uses a default path separator of \ if the USEP environment variable is set to \ and a default path separator of / otherwise.

  7. ls -a a:

    List all files and subdirectories in the current directory of the A drive.

  8. ls -lsh *

    This command lists only hidden and system files in the current directory, along with their mode (attributes), sizes, and time and date stamps.

  9. ls -d *

    This command lists all subdirectories within the current directory. The DOS DIR *. command sort of does the same thing, provided that directory names have no extension and file names always have an extension.

  10. ls -l

    List each file in the current directory, along with its mode, size, and time and date of last modification.

  11. ls -lc

    Like -l, except display each file's time and date of creation (Win32 and OS/2 versions only).

  12. ls -lu

    Like -l, except display each file's time and date of last access (NTFS and HPFS only).

  13. ls -R c:/[a-m]*.exe

    List all .exe files on drive C that begin with the letters A through M, inclusive.

  14. ls -R c:/my.bat

    List all occurances of the my.bat file on drive C. This command performs a ``whereis'' type of function.

  15. ls -R *.c

    List all .c files in the current directory and, recursively, in any subdirectories within the current directory.

  16. ls -lRdn /

    List all directories on the current drive in ``long'' format, sorted by directory name.

  17. ls -lt

    List all files in the current directory in ``long'' format, sorted by date and time of modification.

  18. ls -lut

    List all files in the current directory in ``long'' format, sorted by date and time of last access (NTFS and HPFS only).

  19. ls -luo

    List all files in the current directory in ``long'' format, in the order in which they occur in the directory (unsorted). Display the time of last access for each one.

  20. ls -lRn
    ls -l -Rn
    ls -l -R -n

    You may specify flags in one or more groups. For example, these commands all produce identical results.

  21. ls -lC1

    The same command as ls -1. The C flag disables the l flag, and the 1 flag in turn disables the C flag.