ArticleslgStudy

science

Ls

Ls is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Ls rather than just read about it. In short: ls is a shell command for listing files – including special files such as directories. Originally developed for Unix and later codified by POSIX and Single UNIX Specification, it is supported in many operating systems today, including Unix-like variants, Windows (via PowerShell and UnxUtils), EFI, and MSX-DOS (via MSX-DOS2 Tools).

Ls — main illustration
Ls — illustration

Key takeaways

  • Ls belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Ls to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Ls from memory before moving on to harder problems.

Reference excerpt

ls is a shell command for listing files – including special files such as directories. Originally developed for Unix and later codified by POSIX and Single UNIX Specification, it is supported in many operating systems today, including Unix-like variants, Windows (via PowerShell and UnxUtils), EFI, and MSX-DOS (via MSX-DOS2 Tools). The numerical computing environments MATLAB and GNU Octave include an ls command with similar functionality. An ls command appeared in the first version of AT&T UNIX. The name inherited from Multics and is short for "list". 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. In MS-DOS, OS/2, and Windows, the equivalent command is dir. Apple DOS for the Apple II uses CATALOG.

Behavior When invoked with no path argument, ls lists the files of the working directory. Otherwise, it includes each specified file and each file of a specified directory. Common options include:

-a Includes all files, even those starting with ., which on Unix-based systems are otherwise not included -A Same as -a, but excludes the special entries . (working directory) and .. (parent of working directory) -l Selects the long output format which extends the default output of the file name with additional information including type (- for regular file, d for directory, l for symbolic link, n for network file, s for socket, p for named pipe (FIFO), c for character special file, bfor block special file), permissions, hard link count, owning user and group, size, last-modified timestamp -h Output sizes as so-called human readable by using units of KB, MB, GB instead of bytes. This option is not part of the POSIX standard, although implemented in several systems, e.g., GNU coreutils in 1997, FreeBSD 4.5 in 2002, and Solaris 9 also in 2002. -R Include files of a directory tree, recursively -t Sort the list by modification time (default sort is alphabetically) -u Sort the list by last access time -c Sort the list by last attribute (status) change time -r Reverse the order, for example most recent time last --full-time Show times down to the millisecond instead of just the minute -1 One entry per line -m Stream format; list items across the page, separated by commas. -g Include group but not owner -o Include owner but not group (when combined with -g both group and owner are suppressed) -d Show information about a directory or symbolic link, rather than the contents of a directory or the link's target -F Append a "/" to directory names, a "*" to executable files and a "@" to symbolic links

Example The following example shows the long form output:

Each output line includes a file type letter ('-' for file, 'd' for directory), 9 letters representing permissions, the number of hard links, owning user, owning group, size, modification date, 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.

Some implementations support color output to indicate metadata. GNU ls provides the --color option which enables using a database to control colors maintained using dircolors. FreeBSD ls provides the -G option which enables using the termcap database The following example shows possible color output:

-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

See also stat (Unix) – Unix system call for querying file metadataPages displaying short descriptions of redirect targets chown – Shell command for changing the owner of a file chgrp – Shell command for changing the group of a file du (Unix) – Shell command for reporting file system storage use mdls – Search feature found on Apple devicesPages displaying short descriptions of redirect targets User identifier (Unix) – Value identifying a user account in Unix and Unix-like operating systemsPages displaying short descriptions of redirect targets Group identifier (Unix) – Unix/POSIX system account group number; numeric value used to represent a specific groupPages displaying short descriptions of redirect targets List of POSIX commands Unix directory structure – Directory structure used by a Unix-like operating systemPages displaying short descriptions of redirect targets

References

External links

ls – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group ls(1) – FreeBSD General Commands Manual ls(1) – NetBSD General Commands Manual ls(1) – OpenBSD General Commands Manual ls(1) – Solaris 11.4 User Commands Reference Manual ls(1) – Linux User Manual – User Commands from Manned.org ls(1) – Plan 9 Programmer's Manual, Volume 1 ls(1) – Inferno General commands Manual GNU ls source code (as part of coreutils) ls at the LinuxQuestions.org wiki

Illustrations

Ls illustration

Worked examples

Example 1 — a first encounter with Ls

Start with the simplest possible case. Write down what Ls claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Ls before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Ls ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Ls

In research
Ls appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Ls in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Ls is common in secondary-school and first-year university syllabi. It links to neighbouring topics IBM i Qshell commands, Inferno (operating system) commands, Multics commands, so understanding it makes those chapters shorter.
In everyday life
Look for Ls outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Ls” →

How to study Ls in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Ls means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Ls out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Ls in simple terms?

ls is a shell command for listing files – including special files such as directories. Originally developed for Unix and later codified by POSIX and Single UNIX Specification, it is supported in many operating systems today, including Unix-like variants, Windows (via PowerShell and UnxUtils), EFI…

Why does Ls matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Ls?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Ls.

Tags

  • IBM i Qshell commands
  • Inferno (operating system) commands
  • Multics commands
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities

Keep exploring