Professional Documents
Culture Documents
Accessing command
line(CLI)
GOAL
• Log in to a Linux system and run simple commands using the shell.
OBJECTIVES
• Log in to a Linux system on a local text console and run simple commands using
the shell.
• Log in to a Linux system using the GNOME desktop environment and run
commands from a shell prompt in a terminal program.
• Save time by using tab completion, command history, and command editing
shortcuts to run commands in the Bash shell.
SECTIONS
• Accessing the Command Line (and Quiz)
• Accessing the Command Line Using the
• Desktop (and Guided Exercise)
• Executing Commands Using the Bash Shell (and Quiz)
LAB
• Accessing the Command Line
INTRODUCTION TO THE BASH
SHELL
• A command line is a text-based interface which can be used to input
instructions to a computer system. The Linux command line is provided
by a program called the shell.
• The default shell for users in Red Hat Enterprise Linux is the GNU
Bourne-Again Shell (bash). Bash is an improved version of one of the
most successful shells used on UNIX-like systems, the Bourne Shell (sh).
• When a shell is used interactively, it displays a string when it is waiting
for a command from the user. This is called the shell prompt. When a
regular user starts a shell, the default prompt ends with a $ character,
as shown below.
• The $ character is replaced by a # character if the shell is running as the superuser,
root. This makes it more obvious that it is a superuser shell, which helps to avoid
accidents and mistakes which can affect the whole system. The superuser shell
prompt is shown below.
• Using bash to execute commands can be powerful. The bash shell provides a
scripting language that can support automation of tasks. The shell has additional
capabilities that can simplify or
• make possible operations that are hard to accomplish efficiently with graphical
tools.
SHELL BASICS
• Commands entered at the shell prompt have three basic parts:
• Command to run (name of the program to run)
• Options to adjust the behavior of the command
• Arguments, which are typically targets of the command
• Tab completion can be used to complete file names when typing them
as arguments to commands.
continuing a long command on another
line that support many options and arguments can quickly grow quite long and are
• Commands
automatically scrolled by the Bash shell. As soon as the cursor reaches the right margin of the
window, the command continues on the next line. To make the readability of the command easier,
you can break it up so that if fits on more than one line.
• To do this, add a backslash character (\) as the last character on the line. This tells the shell to
ignore the newline character and treat the next line as if it were part of the current line. The Bash
shell will start the next line with the continuation prompt, usually a greater-than character (>),
which indicates that the line is a continuation of the previous line. You can do this more than once.
COMMAND HISTORY
• The history command
displays a list of previously
executed commands
prefixed with a command
number.
• Use Exclamation to re-
execute recent command
by matching command
name or by command
number
• The arrow keys can be used
to navigate through
previous commands in the
shell's history.
• UpArrow edits the previous
command in the history list.
DownArrow edits the next
command in the history list.
Login and Logout
• To run the shell, you need to log in to the computer on a terminal. A terminal
is a text-based interface used to enter commands into and print output from a
computer system. There are several ways to do this.
• physical console:- The computer might have a hardware keyboard and display for input
and output directly connected to it.
• LOGGING IN OVER THE NETWORK:- most common way to get a shell prompt on a
remote system is to use Secure Shell (SSH).
• Pasword based
• Publickey based
• When you are finished using the shell and want to quit, you can choose one of
several ways to end the session. You can enter the exit command to terminate
the current shell session. Alternatively, finish a session by pressing Ctrl+D.
QUIZ
1. Which term describes the interpreter that executes commands typed as strings?
a. Command
b. Console
c. Shell
d. Terminal
2. Which term describes the visual cue that indicates an interactive shell is waiting for the user to type a
command?
a. Argument
b. Command
c. Option
d. Prompt
3. Which term describes the name of a program to run?
a. Argument
b. Command
c. Option
d. Prompt
QUIZ …
4. Which term describes the part of the command line that adjusts the behavior of a
command?
a. Argument
b. Command
c. Option
d. Prompt
5. Which term describes the part of the command line that specifies the target that
the
command should operate on?
a. Argument
b. Command
c. Option
d. Prompt
Answer
1. Which term describes the interpreter that executes commands typed as strings?
a. Command
b. Console
c. Shell
d. Terminal
2. Which term describes the visual cue that indicates an interactive shell is waiting for the user to type a
command?
a. Argument
b. Command
c. Option
d. Prompt
3. Which term describes the name of a program to run?
a. Argument
b. Command
c. Option
d. Prompt
Answer …
4. Which term describes the part of the command line that adjusts the
behavior of a command?
a. Argument
b. Command
c. Option
d. Prompt
5. Which term describes the part of the command line that specifies the
target that the command should operate on?
a. Argument
b. Command
c. Option
d. Prompt
1. Which Bash shortcut or command separates commands on the same line?
a. Pressing Tab
b. history
c. ;
d. !string
e. Pressing Esc+.
2. Which Bash shortcut or command is used to re-execute a recent command by
matching the command name?
a. Pressing Tab
b. !number
c. !string
d. history
e. Pressing Esc+.
3. Which Bash shortcut or command is used to complete commands, file names, and
options?
a. ;
b. !number
c. history
d. Pressing Tab
e. Pressing Esc+.
• 4. Which Bash shortcut or command re-executes a specific command in the history list?
a. Pressing Tab
b. !number
c. !string
d. history
e. Pressing Esc+.
5. Which Bash shortcut or command displays the list of previous
commands?
a. Pressing Tab
b. !string
c. !number
d. history
e. Pressing Esc+.