Command Line Terminology – Understanding Parts of a Command

commandcommand lineparameterterminology

At the command line I often use "simple" commands like

mv foo/bar baz/bar

but I don't know what to call all the parts of this:

┌1┐ ┌──2───┐
git checkout master
│   └──────3──────┘
└───────4─────────┘

I (think I) know that 1 is a command and 2's an argument, and I'd probably call 3 an argument list (is that correct?).

However, I don't know what to call 4.

How are more complex "commands" labelled?

find transcripts/?.? -name '*.txt' | parallel -- sh -c 'echo $1 $2' {} {/}

I'd appreciate an answer that breaks down what to call 1,2,3,4 and what to call each part of e.g. this "command" above.

It would be great to learn also about other things that are unique/surprising that I haven't included here.

Best Answer

The common names for each part is as follows:

┌1┐ ┌──2───┐
git checkout master
│   └──────3──────┘
└───────4─────────┘
  1. Command name (first word or token of command line that is not a redirection or variable assignment and after aliases have been expanded).

  2. Token, word, or argument to the command. From man bash:

    word: A sequence of characters considered as a single unit by the shell. Also known as a token.

  3. Generally: Arguments

  4. Command line.


The concatenation of two simple commands with a | is a pipe sequence or pipeline:

┌─1┐ ┌──────2──────┐ ┌─2─┐ ┌──2──┐   ┌──1───┐ ┌2┐┌2┐┌2┐┌────2─────┐ ┌2┐ ┌2┐
find transcripts/?.? -name '*.txt' | parallel -- sh -c 'echo $1 $2'  {} {/}
│    └────────────3──────────────┘            └────────────3──────────────┘
└───────────────────────────────────4─────────────────────────────────────┘

Mind that there are redirection and variable assignments also:

┌──5──┐ ┌1┐ ┌─2─┐ ┌─2─┐   ┌───6──┐ ┌1┐ ┌─5─┐
<infile tee file1 file2 | LC_ALL=C cat >file
└─────────7───────────┘   └───────7────────┘
└─────────────────────4────────────────────┘

Where (beside the numbers from above):

  1. redirection.
  2. Variable assignment.
  3. Simple command.

This is not an exaustive list of all the element a command line could have. Such a list is too complex for this short answer.

Related Question