Linux Tutorial / Linux Terminal and Shell Basics: Command Syntax and Finding Help

To run commands on Linux, open a terminal and enter them into a shell. The terminal is the interface where you type and see output; the shell interprets what you type and runs commands. This lesson shows you how to read basic command syntax, distinguish results from errors, and find help when a command is unfamiliar.

What is the difference between a terminal and a shell?

The terminal application is the window that accepts text input and displays results. A shell runs inside it and interprets commands. The shell can handle a built-in command itself or start another program, then display its output in the terminal. Terminal applications may look different, but the basics of writing commands remain similar when they run the same shell.

The examples here use Bash (Bourne Again Shell). Bash is available on both Ubuntu and Rocky Linux, although the shell currently running and the commands installed may differ by system. A remote server may not have a graphical terminal application, but the principles of using a shell are the same.

Open a terminal and find the prompt

In a graphical desktop, search the application list for “Terminal.” The menu name and launch method depend on your desktop environment. When the terminal opens, you will usually see a blinking cursor after text such as your user name or current directory. This is the prompt: the shell is waiting for input.

Your prompt may contain a $ or #, but that character is not part of the command. The code blocks in this lesson contain only what you should type. When a task requires administrator privileges, we will explain when to use sudo instead of relying on the appearance of the prompt.

Type the following command and press Enter:

printf '%s\n' hello

The command prints hello, then the prompt returns:

hello

printf prints text using a format. Here, %s stands for a string and \n adds a newline. It is normal if your actual prompt looks different from one shown elsewhere.

Read the parts of a command

Many commands follow a command + option + argument pattern. The command specifies what to do, an option changes how it works, and an argument identifies what to work on. Not every command needs both options and arguments.

ls -l /etc
Part Example Meaning
Command ls Lists entries.
Option -l Uses a detailed listing format.
Argument /etc Specifies the directory to list.

Spaces separate these parts. In a synopsis such as ls [OPTION] [FILE...], square brackets mean that a part is optional; you do not type the brackets. The ellipsis means that you can specify more than one item. Each command has its own syntax, so check its help when in doubt.

Use quotes when a value containing spaces should be passed as one argument. Compare these commands:

printf '%s\n' hello world
printf '%s\n' 'hello world'

The first command receives hello and world as separate arguments and prints two lines. The second receives one argument and prints one line:

hello
world
hello world

Different kinds of quotes also affect shell expansion in different ways. For now, focus on their basic use for keeping a value with spaces together; variables and expansions belong in a later lesson.

Handle input, output, and errors

After you enter a command and press Enter, the shell runs it. Text on the screen may be a normal result or an error about something such as an unsupported option or a missing file. No output does not necessarily mean failure. Read the message in light of what you asked the command to do.

You can scroll back through long output in the terminal. Press the Up arrow to recall a previous command. Because commands may be kept in shell history, avoid putting passwords or tokens directly into command arguments.

To interrupt a running command, you can usually press Ctrl+C. In a terminal, this sends an interrupt signal to the running command; it is not the usual Copy shortcut. To leave the shell, type exit. Ctrl+D can also exit from an empty input line, but it may have a different effect when another program is waiting for input.

Find help for an unfamiliar command

Check the documentation before guessing an option. External programs and shell built-ins may provide help in different ways.

Method When to use it
command --help Quickly review options if the program supports this flag. Not every command does.
man command Read the installed manual page for detailed syntax and options.
help command Read Bash's help for a shell built-in.
type command Find out whether Bash resolves a name to a built-in, alias, function, or external program.

For example, ls --help gives you a quick look at its options, while man ls provides more detail. Within a manual page, type / followed by a search term to find text, and press q to quit. Some minimal installations do not include the manual page you want.

ls --help
man ls

cd is an example of a Bash built-in. Use type cd to identify it, then help cd to read its usage. The wording of the result can vary with the shell and display language.

type cd
help cd

For more examples, see the separate guides to the man command, the help command, and the type command.

Try a short exercise

  1. Run type printf to see how your current Bash shell interprets printf.
  2. Run help printf and locate the explanation of its format string and arguments.
  3. Run printf '%s\n' 'Linux practice' and check that Linux practice appears on one line.
type printf
help printf
printf '%s\n' 'Linux practice'

The last command produces the following output. The wording from the first two commands may vary with the Bash version and display language.

Linux practice

If you see command not found, check the spelling first. For an error such as invalid option, check the command's help for supported options and syntax. Do not add sudo to every command that reports a permissions error; first find out which file or operation requires permission.

Official documentation

The explanation of the shell and built-ins is based on the GNU Bash Reference Manual: Basic Shell Features and its Bash Builtins section. See the man(1) manual page for manual-page conventions and usage.

More in This Category
Linux diff Command: Compare Text Files and Directories

Linux diff Command: Compare Text Files and Directories

Learn how Linux diff compares text files and directories, produces unified patches, ignores selected whitespace changes, and reports differences through exit status.

Linux fmt Command: Reformat Plain-Text Paragraphs

Linux fmt Command: Reformat Plain-Text Paragraphs

Learn how to reformat Plain-Text Paragraphs with the Linux fmt command, including practical examples, key options, and important precautions.

Linux env Command: Display Variables and Run Commands with a Custom Environment

Linux env Command: Display Variables and Run Commands with a Custom Environment

Learn how to use the Linux env command to display environment variables or run a command with temporary variable values, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux cd Command: Change the Current Directory

Linux cd Command: Change the Current Directory

Learn how to use the Linux cd command to move between directories using absolute, relative, home, and previous paths, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux alias Command: Create Command Shortcuts

Linux alias Command: Create Command Shortcuts

Learn how to use the Linux alias command to create, inspect, and make shell command aliases persistent, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux free Command: Check Memory and Swap Usage

Linux free Command: Check Memory and Swap Usage

Learn how to use the Linux free command to inspect available memory, used memory, cache, and swap usage, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux ss Command: Inspect Open Ports and Sockets

Linux ss Command: Inspect Open Ports and Sockets

Learn how to inspect Open Ports and Sockets with the Linux ss command, including practical examples, key options, and important precautions.

Linux killall Command: Signal Processes by Name

Linux killall Command: Signal Processes by Name

Learn how to signal Processes by Name with the Linux killall command, including practical examples, key options, and important precautions.

Linux stat Command: Display Detailed File Metadata

Linux stat Command: Display Detailed File Metadata

Learn how to use the Linux stat command to inspect file size, permissions, ownership, timestamps, inode, and filesystem metadata, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.