Ls Ls

Ls - Definition

The title given to this article is incorrect due to technical limitations. The correct title is ls.

ls (abbreviated from "list") is a command in Unix-like operating systems. It is similar to "dir" in DOS. In most modern Unix variants, the dir command is also available, but it is simply another way of invoking the ls program.

When executed, the ls command lists the contents of the current directory (or the given arguments). It is a basic utility of the Unix-like command line interface (CLI). As one of the oldest and most popular Unix commands, it has acquired a vast number of options. Modern ls implementations, such as GNU ls, can produce colored output according to customizable configuration files.

Contents

History

An ls utility first appeared in Version 5 AT&T UNIX. Today, two popular versions of ls include the Free Software Foundation's (part of the GNU coreutils package) and the one released by various BSD distributions, such as FreeBSD, OpenBSD, NetBSD, and Apple Computer's Darwin. Both are free software and open source.

Sample ls search

Here is a sample display of its usage:

$ ls -laF
total 4
drwxr-xr-x   10 Brandon  None            0 Sep 30 16:48 ./
drwxr-xr-x   10 Brandon  None            0 Sep 30 16:48 ../
drwxr-xr-x    3 Brandon  None            0 Sep 30 19:02 bin/
-rw-r--r--    1 root     None           89 Dec 16 12:24 test
-rwxr-xr-x    1 Brandon  None           57 Sep 30 19:22 cygwin.bat*
-rw-r--r--    1 Brandon  None          766 Sep 30 19:22 cygwin.ico
drwxr-xr-x   15 Brandon  None            0 Sep 30 16:48 etc/
drwxr-xr-x    3 Brandon  None            0 Sep 30 19:27 home/
drwxr-xr-x   21 Brandon  None            0 Sep 30 19:02 lib/
drwxr-xr-x    2 Brandon  None            0 Sep 30 19:14 sbin/
-rw-r--r--    1 Brandon  None           22 Dec 16 12:24 testb3
drwxr-xr-x    3 Brandon  None            0 Sep 30 19:02 tmp/
drwxr-xr-x   20 Brandon  None            0 Sep 30 19:02 usr/
drwxr-xr-x    6 Brandon  None            0 Sep 30 19:02 var/

Some ls command line options

ls has a number of command line options, or "switches", that can modify the output. Some of these options are:

  • -F: adds a character that denotes the file's type, (/ for directories, * for executables, @ for symlinks)
  • -R: recursively lists contents in all subdirectories
  • -l: long file format, including time, date, permissions and so on.
  • -a: do not hide entries starting with a dot
  • -f: unsorted output

Breakdown of output

The output given by ls in long listing form is broken into columns, as can be seen above. These columns can then be broken down to acquire information about listed files, directories and devices.

This is the tabular form of the first two listed items from the sample above with headings to explain each column:

Type Permissions Number of hard links Owner Group Size Date modified Listing name
d rwxr-xr-x 3 Brandon None 0 Sep 30 19:02 bin/
- rw-r--r-- 1 root None 89 Dec 16 12:24 test

Type column description

The very first character in a long listing gives the type of file.

Character Type
- Normal file
b Block device
c Character device
d Directory
l Symbolic link
p Named pipe (FIFO)
s Domain socket

Permissions description

example:

rwxr-xr--

The first three characters represent the owner's permissions on the item, the next three the group's permissions, the last, everyone else.

Meaning of Characters by Character

As for the individual character meanings, the following is meant to explain that:

r - read permission;
w - write permission;
x - execute permission;
- - no permission;

Example

Given the output above, drwxr-xr--,

  • This item is a directory;
  • The file owner may read write and execute this item myself;
  • The group this file belongs to may read and execute this file but not write to it;
  • Everyone else may read this item but not write to it or execute it

More examples

To only list directories:

ls */ -d

To get colorized output:

ls --color=auto

To get ls to always output the result colorized when appropriate, write the following in .bashrc:

alias ls="ls --color=auto"
Copyright 2009 WordIQ.com - Privacy Policy  :: Terms of Use  :: Contact Us  :: About Us
This article is licensed under the GNU Free Documentation License. It uses material from the this Wikipedia article.