Ls - Behavior

Behavior

Unix and Unix-like operating systems maintain the idea of a current working directory, that is, where one is currently positioned in the hierarchy of directories.

When invoked without any arguments, ls lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed.

Files whose names start with "." are not listed, unless the -a flag is specified, the -A flag is specified, or the files are specified explicitly.

Without options, ls displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:

  • -l long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
  • -F appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
  • -a lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
  • -R recursively lists subdirectories. The command ls -R / would therefore list all files.
  • -d shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
  • -t sort the list of files by modification time.
  • -h print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)

In some environments, providing the option --color (for GNU ls) or -G (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as -F would. To determine what color to use for a file, GNU ls checks the Unix file type, the file permissions, and the file extension, while FreeBSD ls checks only the Unix file type and file permissions.

When the option to use color to indicate file types is selected, the output might look like:

brw-r--r-- 1 unixguy staff 64, 64 Jan 27 05:52 block crw-r--r-- 1 unixguy staff 64, 255 Jan 26 13:57 character -rw-r--r-- 1 unixguy staff 290 Jan 26 14:08 compressed.gz -rw-r--r-- 1 unixguy staff 331836 Jan 26 14:06 data.ppm drwxrwx--x 2 unixguy staff 48 Jan 26 11:28 directory -rwxrwx--x 1 unixguy staff 29 Jan 26 14:03 executable prw-r--r-- 1 unixguy staff 0 Jan 26 11:50 fifo lrwxrwxrwx 1 unixguy staff 3 Jan 26 11:44 link -> dir -rw-rw---- 1 unixguy staff 217 Jan 26 14:08 regularfile

ls has a large number of other options (see: man ls). It is a frequently used tool that provides an interface to the file system via the command line.

On some systems (e.g. PCLinuxOS), ls has an alias of just l. Many systems also alias ls -l to ll or ls -la to la (e.g. PC-BSD).

Read more about this topic:  Ls

Famous quotes containing the word behavior:

    Gaining a better understanding of how children’s minds work at different ages will allow you to make more sense of their behaviors. With this understanding come decreased stress and increased pleasure from being a parent. It lessens the frustrations that come from expecting things that a child simply cannot do or from incorrectly interpreting a child’s behavior in adult terms.
    Lawrence Kutner (20th century)

    There are ... two minimum conditions necessary and sufficient for the existence of a legal system. On the one hand those rules of behavior which are valid according to the system’s ultimate criteria of validity must be generally obeyed, and on the other hand, its rules of recognition specifying the criteria of legal validity and its rules of change and adjudication must be effectively accepted as common public standards of official behavior by its officials.
    —H.L.A. (Herbert Lionel Adolphus)

    School success is not predicted by a child’s fund of facts or a precocious ability to read as much as by emotional and social measures; being self-assured and interested: knowing what kind of behavior is expected and how to rein in the impulse to misbehave; being able to wait, to follow directions, and to turn to teachers for help; and expressing needs while getting along with other children.
    Daniel Goleman (20th century)