Course / 03 Command line / Lesson 01 of 19

What a command is

Estimated time: 15 min reading · 15 min activity

You can ask a computer to do something by typing a command. For example, a command can display a message or list the files in a folder. In this lesson, you will read a short command before trying one yourself.

The terminal is the window where you type and read the response. Inside that window, a program called a shell reads your instructions. The Ubuntu practice environment uses a shell called Bash.

When the shell is ready, it displays a prompt beside the place where you type. The prompt might include your username or current folder. Examples often shorten it to a dollar sign, $. You type after that sign. The example below separates the command from its expected result.

Before you begin

Estimated time
15 min reading, 15 min activity. Setup and optional practice may take longer.
Where you work
Use the Bash terminal in your Ubuntu practice environment. These activities display text and list names; they do not create or change files. You can also complete the lesson in a browser with paper or a text editor. No account or paid tool is needed.
Without a lab
The example and worksheet show the commands and their expected results. If you cannot use a terminal, write down what each command would do and explain which parts you would type. This practices reading commands; running them can wait until your lab is available. Answer checking and saved progress require JavaScript and browser storage.

After this lesson you can:

  • Separate a shell prompt from the command you type.
  • Identify a command name, an argument, and an option in short examples.
  • Predict what a print command displays, then compare it with your result.

01Example

This command asks printf to display the word hello and then start a new line. Read the two parts below: the first is what you type, and the second is what you should see. The result is an expected example.

Command to type:
printf '%s\n' hello

Expected result:
hello

The same command shown beside a sample prompt:
$ printf '%s\n' hello

02Read a command before entering it

Start with the command name: printf. The words after it are arguments, which supply information to the command. Here, one argument describes how to display the text, and the next argument is the text hello.

The format '%s\n' has two parts. %s means to display a string, or piece of text. The backslash and n, written \n, mean to start a new line after it. Together, they tell printf how to display hello.

The straight single quotes around '%s\n' keep those characters together for the shell to pass to printf. The shell removes the surrounding quotes before passing the argument, so the quote marks are not printed.

An option is an argument that changes a command's behavior. For example, ls lists names in a folder. In ls -a, the option -a includes names beginning with a dot that the usual listing leaves out. You will work with those files in the filesystem lesson.

Before pressing Enter, identify the command and what its arguments ask it to do. Later commands can change files or contact another computer. Reading the whole line helps you notice those effects.

Read prompt, command and arguments separately; hello appears in a distinct predicted-output panel.Model. A teaching model drawn by hand. It shows the idea, not real tool output.

Read the full explanation below.

Syntax with sample prompt

$ printf '%s\n' hello
Sample promptCommand nameFormat argumentValue argument

Predicted stdout

hello
 
One predicted line
What this part means

The $ marks the sample prompt; type the command after it.

The prompt is not typed.

The $ marks the sample prompt; type the command after it.

Follow the explanation

  1. The $ marks the sample prompt; type the command after it.
  2. printf receives a format argument and the hello value argument.
  3. The hello argument is formatted into one output line.
Read every state and value

1. The $ marks the sample prompt; type the command after it.

Selected parts
Sample prompt
Explanation
prompt-note

2. printf receives a format argument and the hello value argument.

Selected parts
Command name · Format argument · Value argument
Explanation
args

3. The hello argument is formatted into one output line.

Selected parts
Value argument · One predicted line
Explanation
result
Read prompt, command and arguments separately; hello appears in a distinct predicted-output panel.

03Try a harmless printed line

Use the worksheet below to practice with a new message. Your goal is to explain the input and the result. If you are working on paper, predict each result instead of running the command.

Command activity worksheet
Read the worked hello example in the lesson, then try this new message.

Command to type:
printf '%s\n' 'practice note'

Expected result:
practice note

Identify the command name, the format argument, and the message argument.
Explain why the two words appear together on one line.

Then enter this separate command:
ls -a

It lists names in your current folder, including names beginning with a dot.
Your folder's names will vary. Identify the command and its option.

Prompt practice:
$ pwd

The dollar sign represents the shell's prompt.
Which part would you type? Use the prompt explanation in the lesson.

Download the command practice worksheet

  1. Open Terminal in your Ubuntu practice environment. Find the prompt and the place where your typing will appear. Your prompt does not need to look like the example's dollar sign.
  2. Read the activity command in the worksheet. Predict the text it will display, including whether the two words stay on one line.
  3. Type printf '%s\n' 'practice note' and press Enter. Type only the command, without the sample prompt. The expected result is practice note on one line, followed by a new prompt.
  4. Compare the command with the hello example. printf and the format stayed the same; the message changed. The quotes around 'practice note' make those two words one argument, so printf displays them together.
  5. As a separate command, type ls -a and press Enter. It lists names in your current folder, including names beginning with a dot. The names depend on your folder. Identify ls as the command and -a as its option; you do not need to recognize every listed name yet.
  6. Write one sentence explaining the difference between a prompt, a command, and its result. You can leave the terminal open for the next lesson or close it normally. These activities need no cleanup.

04Optional challenge

Allow about ten minutes. Compare printf '%s\n' 'two words' with printf '%s\n' two words. Predict how many lines each displays before trying either command.

Check your reasoning: quotes make 'two words' one argument, so it appears on one line. Without quotes, two and words are separate arguments. printf reuses this format for each one, producing two lines.

05What to remember

A prompt shows where the shell is ready for input. The command name tells it what to run, and arguments provide the information it needs. Options are arguments that change its behavior.

Next, you will learn how to find your current folder. That matters because many commands use it as their starting location.

06Fresh cases for the checks

Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.

Command card A: a line beside a sample Bash promptOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

$ ls -a Shelf
The leading $ is the displayed prompt. Shelf names the folder to list.
This is a fictional command-reading case, not a recorded terminal run.

Command card B: predict a different messageOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Command to read, without a prompt:
printf '%s\n' 'River crossing'
Predict only its displayed message. No files are read or changed.

Command card C: a copied prompt errorOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

The example uses $ as its prompt marker.
A learner types this entire line after their own Bash prompt:
$ printf '%s\n' Beacon
Bash reports that the command named $ was not found.

Command card D: independent prediction and supplied resultOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Command shown without a prompt:
printf '%s\n' meadow path
Learner prediction: meadow path on one line.
Supplied expected result, between the markers:
BEGIN RESULT
meadow
path
END RESULT
This result is a teaching prediction, not execution evidence.

07Explain what you would type

Optional self-check: write two or three sentences explaining how you would read a new command beside a sample prompt before entering it. Include how you would compare predicted and actual printed text.

Review your explanation: distinguish prompt, command name, option and other arguments; explain what quotes group; and compare text and line breaks while keeping expected results separate from observations. This explanation is self-reviewed.

08Common mistakes

If a copied command fails, compare what you typed with the line labeled Command to type. Remove a copied prompt marker such as $, while keeping the command and its arguments.

If Enter takes you to another input line instead of displaying a result, check for a missing closing quote. Press Ctrl+C to cancel the unfinished input, then type the line again with matching straight single quotes.

If the message appears on two lines, check the quotes around 'practice note'. The quotes keep the two words in one argument.

If the commands behave differently in Command Prompt or PowerShell, return to the Ubuntu Bash environment used here. You can use the worksheet until that environment is available.

References

  • Bash manual: simple commands

    Explains how Bash reads a command name and passes the remaining words as arguments. Optional reference; the lesson supplies the examples you need.

  • Bash manual: quoting

    Describes straight single quotes and how they preserve the characters inside an argument.

  • Bash manual: printf

    Find printf in this section for format strings and how a format is reused when there are additional arguments.