What’s a Command?

A Linux command typically consists of a program name followed by options and arguments, typed within a shell, like this:

$ wc -l myfile

The program name (wc, the “word count” program) refers to a program somewhere on disk that the shell will locate and run. Options, which usually begin with a dash, affect the behavior of the program. In the preceding command, the -l option tells wc to count lines rather than words. The argument myfile specifies the file that wc should read and process. The leading dollar sign ($) is a prompt from the shell, indicating that it is waiting for your command.

Commands can have multiple options and arguments. Options may be given individually:

$ wc -l -w myfile           Two individual options

or combined behind a single dash:

$ wc -lw myfile             Same as -l -w

though some programs are quirky and do not recognize combined options. Multiple arguments are also OK:

$ wc -l myfile1 myfile2     Count lines in two files

Options are not standardized. The same option letter (say, -l) may have different meanings to different programs: in wc -l it means “lines of text,” but in ls -l it means “longer output.” In the other direction, two programs might use different options to mean the same thing, such as -q for “run quietly” versus -s for “run silently.”

Likewise, arguments are not standardized, unfortunately. They usually represent filenames for input or output, but they can be other things too, like directory names or regular expressions.

Commands can be more complex and interesting than a single program with options:

  • Commands can run more than one program at a time, either in sequence (one program after another) or in a “pipeline” with the output of one command becoming the input of the next. Linux experts use pipelines all the time.

  • The Linux command-line user interface—the shell—has a programming language built in. So instead of a command saying “run this program,” it might say, “if today is Tuesday, run this program; otherwise, run another command six times for each file whose name ends in .txt.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.125.219