Ls

Last updated
ls
Original author(s) coreutils: Richard Stallman and David MacKenzie
Developer(s) Various open-source and commercial developers
Written in C
Operating system Multics, Unix, Unix-like, Plan 9, Inferno, MSX-DOS
Type Command
License coreutils: GPLv3+
BusyBox: GPL-2.0-only
Toybox: 0BSD
Plan 9: MIT License

In computing, ls is a command to list computer files and directories in Unix and Unix-like operating systems. It is specified by POSIX and the Single UNIX Specification.

Contents

It is available in the EFI shell, [1] as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities, [2] or as part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2. [3]

The numerical computing environments MATLAB and GNU Octave include an ls function with similar functionality. [4] [5]

In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir command.

History

An ls utility appeared in the first version of AT&T UNIX, the name inherited from a similar command in Multics also named 'ls', short for the word "list". [6] [7] [8] ls is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. [9]

Behavior

Unix and Unix-like operating systems maintain the idea of a working directory. When invoked without arguments, ls lists the files in the working directory. If a directory is specified as an argument, the files in that directory are listed; if a file is specified, that file is listed. Multiple directories and files may be specified.

In many Unix-like systems, names starting with a dot (.) are hidden. Examples are ., which refers to the working directory, and .., which refers to its parent directory. Hidden names are not shown by default. With -a, all names, including all hidden names, are shown. Using -A shows all names, including hidden names, except for . and ... File names specified explicitly (for example ls .secret) are always listed.

Without options, ls displays names only. The different implementations have different options, but common options include:

Additional options controlling how items are displayed include:

It may be possible to highlight different types of items with different colors. This is an area where implementations differ:

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

The first letter can be one of 8 characters: -, regular file; d, directory; l, symbolic (soft) link; n, network files; s, socket; p, named pipe (FIFO); c, character special file; b, block special file.

-rw-r--r--    1 tsmitt nregion   26650 Dec 20 11:16 audio.ogg brw-r--r--    1 tsmitt nregion      64 Jan 27 05:52 bd-block-device crw-r--r--    1 tsmitt nregion     255 Jan 26 13:57 cd-character-device -rw-r--r--    1 tsmitt nregion     290 Jan 26 14:08 image.png drwxrwxr-x    2 tsmitt nregion      48 Jan 26 11:28 di-directory -rwxrwxr-x    1 tsmitt nregion      29 Jan 26 14:03 ex-executable -rw-r--r--    1 tsmitt nregion       0 Dec 20 09:39 fi-regular-file lrwxrwxrwx    1 tsmitt nregion       3 Jan 26 11:44 ln-soft-link -> dir lrwxrwxrwx    1 tsmitt nregion      15 Dec 20 10:57 or-orphan-link -> mi-missing-link drwxr-xrwx    2 tsmitt nregion    4096 Dec 20 10:58 ow-other-writeable-dir prw-r--r--    1 tsmitt nregion       0 Jan 26 11:50 pi-pipe -rwxr-sr-x    1 tsmitt nregion       0 Dec 20 11:05 sg-setgid srw-rw-rw-    1 tsmitt nregion       0 Jan 26 12:00 so-socket drwxr-xr-t    2 tsmitt nregion    4096 Dec 20 10:58 st-sticky-dir -rwsr-xr-x    1 tsmitt nregion       0 Dec 20 11:09 su-setuid -rw-r--r--    1 tsmitt nregion   10240 Dec 20 11:12 compressed.gz drwxrwxrwt    2 tsmitt nregion    4096 Dec 20 11:10 tw-sticky-other-writeable-dir

Sample usage

The following example demonstrates the output of the command:

$ ls-l drwxr--r--   1 fjones editors     4096 Mar  2 12:52  drafts-rw-r--r--   3 fjones editors    30405 Mar  2 12:52  edition-32-r-xr-xr-x   1 fjones bookkeepers 8460 Jan 16  2022  edit.sh

Each line shows the d (directory) or - (file) indicator, Unix file permission notation, number of hard links (1 or 3), the file's owner, the file's group, the file size, the modification date/time, and the file name. In the working directory, the owner fjones has a directory named drafts, a regular file named edition-32, and an executable named edit.sh which is "old", i.e. modified more than 6 months ago as indicated by the display of the year.

┌─────────── file (not a directory)|┌─────────── read-write (no execution) permissions for the owner|│  ┌───────── read-only permissions for the group|│  │  ┌─────── read-only permissions for others|│  │  │     ┌── number of hard links|│  │  │     │   ┌── owner|│  │  │     │   │     ┌── user group|│  │  │     │   │     │          ┌── file size in bytes|│  │  │     │   │     │          │    ┌── last modified on|│  │  │     │   │     │          │    │                ┌── filename-rw-r--r--   3 fjones editors    30405 Mar  2 12:52  edition-32

See also

Related Research Articles

In Unix and Unix-like operating systems, chmod is the command and system call used to change the access permissions and the special mode flags of file system objects. Collectively these were originally called its modes, and the name chmod was chosen as an abbreviation of change mode.

uniq is a utility command on Unix, Plan 9, Inferno, and Unix-like operating systems which, when fed a text file or standard input, outputs the text with adjacent identical lines collapsed to one, unique line of text.

dir (command) Directory information command on various operating systems

In computing, dir (directory) is a command in various computer operating systems used for computer file and directory listing. It is one of the basic commands to help navigate the file system. The command is usually implemented as an internal command in the command-line interpreter (shell). On some systems, a more graphical representation of the directory structure can be displayed using the tree command.

pwd Directory information command on various operating systems

In Unix-like and some other operating systems, the pwd command writes the full pathname of the current working directory to the standard output.

head (Unix) Program on Unix and Unix-like systems

head is a program on Unix and Unix-like operating systems used to display the beginning of a text file or piped data.

ln (Unix) Unix file management utility

The ln command is a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file or directory. The use of a hard link allows multiple filenames to be associated with the same file since a hard link points to the inode of a given file, the data of which is stored on disk. On the other hand, symbolic links are special files that refer to other files by name.

patch (Unix) Unix utility to apply changes to text files

The computer tool patch is a Unix program that updates text files according to instructions contained in a separate file, called a patch file. The patch file is a text file that consists of a list of differences and is produced by running the related diff program with the original and updated file as arguments. Updating files with patch is often referred to as applying the patch or simply patching the files.

tr (Unix) Unix text formatting utility

tr is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.

cp (Unix) Unix command utility

In computing, cp is a command in various Unix and Unix-like operating systems for copying files and directories. The command has three principal modes of operation, expressed by the types of arguments presented to the program for copying a file to another file, one or more files to a directory, or for copying entire directories to another directory.

split is a utility on Unix, Plan 9, and Unix-like operating systems most commonly used to split a computer file into two or more smaller files.

df (Unix) Standard Unix command

df is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access. df is typically implemented using the statfs or statvfs system calls.

In computing, umask is a command that determines the settings of a mask that controls how file permissions are set for newly created files. It may also affect how the file permissions are changed explicitly. umask is also a function that sets the mask, or it may refer to the mask itself, which is formally known as the file mode creation mask. The mask is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files. The bits in the mask may be changed by invoking the umask command.

who (Unix)

The standard Unix command who displays a list of users who are currently logged into the computer.

mv is a Unix command that moves one or more files or directories from one place to another. If both filenames are on the same filesystem, this results in a simple file rename; otherwise the file content is copied to the new location and the old file is removed. Using mv requires the user to have write permission for the directories the file will move between. This is because mv changes the content of both directories involved in the move. When using the mv command on files located on the same filesystem, the file's timestamp is not updated.

The seven standard Unix file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket as defined by POSIX. Different OS-specific implementations allow more types than what POSIX requires. A file's type can be identified by the ls -l command, which displays the type in the first character of the file-system permissions field.

rm (Unix) Unix command utility

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.

tail is a program available on Unix, Unix-like systems, FreeDOS and MSX-DOS used to display the tail end of a text file or piped data.

In computing, sleep is a command in Unix, Unix-like and other operating systems that suspends program execution for a specified time.

sort (Unix) Standard UNIX utility

In computing, sort is a standard command line program of Unix and Unix-like operating systems, that prints the lines of its input or concatenation of all files listed in its argument list in sorted order. Sorting is done based on one or more sort keys extracted from each line of input. By default, the entire input is taken as sort key. Blank space is the default field separator. The command supports a number of command-line options that can vary by implementation. For instance the "-r" flag will reverse the sort order.

cat (Unix) Unix command utility

cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to (con)catenate files. It has been ported to a number of operating systems.

References

  1. "EFI Shells and Scripting". Intel. Archived from the original on September 27, 2013. Retrieved 2013-09-25.
  2. "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  3. "MSX-DOS2 Tools User's Manual - MSX-DOS2 TOOLS ユーザーズマニュアル". April 1, 1993 via Internet Archive.
  4. "List folder contents - MATLAB ls".
  5. "Function Reference: Ls". Octave Forge.
  6. "Multics manual page for ls or list command". 14 February 1985.
  7. Fischer, Eric. "A Brief History of the 'ls' command". The Linux Documentation Project .
  8. "Multics programmer's manual - Commands and active functions" (PDF). p. 397.
  9. ls   Shell and Utilities Reference, The Single UNIX Specification , Version 4 from The Open Group
  10. "(decode_switches): -h and -H override output units". coreutils.git. 1997-12-31.
  11. "[base] Log of /stable/10/bin/ls/ls.c". 2001-12-28.
  12. What's New in the Solaris 9 Operating Environment, Sun Microsystems, 2002
  13. "General output formatting (GNU Coreutils 9.1)". www.gnu.org. Retrieved 2023-01-07.
  14. "FreeBSD Man Pages ls" . Retrieved June 23, 2013.