Entering commands at the command prompt

Commands issued to the shell on a Linux system generally consist of four components:

  • A valid command (a shell built-in, program, or script found among directories listed in the PATH, or an explicitly defined program)

  • Command options, usually preceded by a dash

  • Arguments

  • Line acceptance (i.e., pressing the Enter key), which we assume in the examples

Each command has its own unique syntax, although most follow a fairly standard form. At minimum, a command is necessary:

$ ls

This simple command lists the contents of the current working directory. It requires neither options nor arguments. Generally, options are letters or words preceded by a single or double dash and are added after the command and separated from it by a space:

$ ls -l

The -l option modifies the behavior of ls by listing files in a longer, more detailed format. In most cases, single-dash options can be either combined or specified separately. To illustrate this, consider these two equivalent commands:

$ ls -l -a
$ ls -la

By adding the -a option, ls displays files beginning with a dot (which it hides by default). Adding that option by specifying -la yields the same result. Some commands offer alternative forms for the same option. In the preceding example, the -a option can be replaced with --all:

$ ls -l --all

These double-dash, full-word options are frequently found in programs from the GNU project. They cannot be combined like the single-dash options can. Both types of options can be freely ...

Get LPI Linux Certification in a Nutshell, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.