NDG Linux Essentials 2.21 | Command Line Skills Module 5 | Chapter 05 Exam Answers Full 100% 2023 and 2024

These are questions of Cisco NDG Linux Essentials 2.21 Command Line Skills Chapter 05 Exam Answers full 100% with the latest version and updated in 2023 and 2024. All answers are verified by experts with explanations.

  1. Which environment variable contains a list of directories that is searched for commands to execute?

    • PS1
    • PS2
    • EXEC
    • PATH
    • Answers Explanation & Hint:

      The environment variable that contains a list of directories that is searched for commands to execute is PATH.

      When you enter a command in the terminal, the shell searches for that command in the directories listed in the PATH variable. If the command is found in one of the directories, it can be executed directly by typing its name in the terminal. If the command is not found in any of the directories listed in PATH, you will get a “command not found” error.

  2. Select the command that can report the location of a command:

    • what
    • which
    • where
    • Answers Explanation & Hint:

      The command that can report the location of a command in Linux is which.

      The which command is used to locate the binary executable corresponding to the given command in the directories listed in the PATH environment variable. When you run which followed by a command name, it will display the full path to the executable of that command, showing you the location of the command’s binary on the system

  3. A pair of single quotes (') will prevent the shell from interpreting any metacharacter.

    True or False?

    • True
    • False
    • Answers Explanation & Hint:

      A pair of single quotes (') will prevent the shell from interpreting most metacharacters, but it will still allow the shell to interpret single quotes (') themselves. Inside single quotes, variables and most special characters are not expanded or interpreted. This is useful when you want to ensure that a string is treated literally and doesn’t undergo any changes by the shell.

      However, if you need to use single quotes within a single-quoted string, you have to temporarily break out of the single quotes, insert the single quote using other means (e.g., \'), and then re-enter the single quotes.

  4. A pair of double quotes (") will prevent the shell from interpreting any metacharacter.

    True or False?

    • True
    • False
    • Answers Explanation & Hint:

      A pair of double quotes (") will prevent the shell from interpreting some metacharacters, but it allows the shell to interpret variables and certain other metacharacters. Inside double quotes, variables will be expanded, meaning their values will be substituted into the string. However, most other special characters (such as wildcard characters like * or commands enclosed in backticks) are treated literally within double quotes. If you want to prevent all metacharacters from being interpreted and use the string exactly as it is, you would use single quotes (') as mentioned in the previous answer.

  5. Using a pair of back quotes (`) will cause a shell to execute the back-quoted text as a command and substitute the output back into the original command.

    True or False?

    • True
    • False
    • Answers Explanation & Hint:

      Using a pair of back quotes (`) in shell scripting is known as command substitution. When you enclose a command within back quotes, the shell executes that command and substitutes the output of the command back into the original command. Note that the use of backticks for command substitution is an older method, and modern shell scripting encourages using the $() syntax for command substitution, which provides better readability and nesting capabilities.

  6. The semicolon (;) can be used to separate multiple commands to be executed in order.

    True or False?

    • True
    • False
    • Answers Explanation & Hint:

      The semicolon (;) is used in shell scripting to separate multiple commands on a single line. When you use a semicolon to separate commands, the shell will execute each command sequentially, one after the other, in the order they appear on the line.

      For example:

      echo "Hello"; date; ls -l

      In this example, three commands are separated by semicolons. The shell will execute them in the following order:

      1. echo "Hello": Prints “Hello” to the console.
      2. date: Displays the current date and time.
      3. ls -l: Lists the files and directories in the current directory with detailed information.

      The semicolon allows you to chain together multiple commands on a single line, which can be useful for scripting or performing several operations in sequence. However, be mindful of the order of execution, as the commands are run one after the other without any condition or error handling.

  7. The double ampersand characters (&& ) are used to separate commands to be executed conditionally, where if the command to the left of the ampersands fails, then the command to the right of the ampersands will be executed.

    True or False?

    • True
    • False
    • Explanation & Hint:

      The double ampersand characters (&&) in command line environments (like Bash) are actually used to chain commands together where the command on the right of the && is executed only if the command on the left succeeds. If the command on the left fails, the command on the right will not be executed.

  8. To be able to output messages to the screen, use the _______ command:

    • type
    • display
    • echo
    • print
    • Explanation & Hint:

      To output messages to the screen, use the echo command. This command is commonly used in shell scripting to display lines of text or variables to the terminal.

  9. The _______ command will print a list of the commands that you’ve previously executed.

    • list
    • eval
    • history
    • exec
    • Explanation & Hint:

      The history command will print a list of the commands that you’ve previously executed. This command is used in many shell environments to display the command history list

  10. To execute the same command as previously executed five commands ago, you would type:

    • @-5
    • &5
    • !-5
    • !5
    • Explanation & Hint:

      To execute the same command as previously executed five commands ago, you would type: !-5

      This uses the history expansion feature in many shells like Bash, where !-n refers to the nth command before the current one in the command history.

  11. The shell program interprets the commands you type into the terminal into instructions that the Linux operating system can execute.

    True or False?

    • True
    • False
    • Explanation & Hint:

      The shell is a critical component in Linux and other Unix-like operating systems that acts as an intermediary between the user and the kernel, which is the core of the operating system. When you type commands into the terminal, the shell interprets these commands and converts them into a format that the operating system can understand and act upon. Here’s a breakdown of how this process works:

      1. Command Input: When you enter a command in the terminal, the shell reads this input. The command could be a built-in shell command or an external program.
      2. Parsing: The shell parses the command to understand what actions are being requested. It breaks the command into the command name and its arguments and handles any special characters or operators (like redirection or piping).
      3. Execution: After parsing the command, the shell executes it. If it’s a built-in command, the shell itself handles the operation. If it’s an external program, the shell locates the program’s executable file, sets up the execution environment, and starts the program.
      4. System Call: For many commands, especially those that affect system files and processes, the shell makes system calls to the kernel. System calls are requests in a Unix-like operating system by an active process for a service performed by the kernel, such as input/output operations, creating and executing new processes, and communicating with integral system components.
      5. Output/Result: The shell then displays the results of the command execution to the user in the terminal, or it might redirect the output to a file or another program, depending on any redirection or piping specified in the command.

      The shell enables users to interface effectively with the system without needing to know or manage the intricate details of the kernel or hardware, providing both an environment for running programs and a scripting language to automate complex sequences of commands.

  12. The acronym CLI stands for:

    • Computer Link Interpreter
    • Command Line Interpreter
    • Command Line Interface
    • Computer Line Interface
    • Explanation & Hint:

      The acronym CLI stands for: Command Line Interface

      This term refers to the text-based interface used for entering commands directly to a computer’s operating system or software by typing text.

  13. What one character treats the character that follows it as if it was surrounded by single quotes?

    • \
    • #
    • /
    • %
    • Explanation & Hint:

      The character that treats the character that follows it as if it was surrounded by single quotes, effectively escaping it, is the backslash (\). This escape character is used in many programming and scripting contexts to indicate that the following character should be treated literally, rather than as part of the language syntax.

  14. The echo command:

    • Tests a variable for duplication
    • Copies variables from one to another
    • Is used to output text to the console
    • Duplicates the input stream to the output stream
    • Is used for variable assignment
    • Explanation & Hint:

      The echo command: Is used to output text to the console

      This command is commonly used in shell scripting and command lines to display a line of text or a value stored in a variable. It outputs the strings it is given as arguments to the standard output, which is typically the display screen.

  15. The most common shell used for Linux distributions is the ________ shell.

    • Zsh
    • Bash
    • Tsch
    • Fish
    • Explanation & Hint:

      The most common shell used for Linux distributions is the Bash shell.

      Bash, which stands for Bourne Again SHell, is widely adopted as the default shell in most Linux distributions due to its versatility and extensive scripting capabilities. It is an enhancement of the original Bourne shell (sh).

  16. HOME is an example of _________.

    • A local variable
    • An environment variable
    • A path variable
    • An internal command
    • An alias
    • Explanation & Hint:

      HOME is an example of an environment variable.

      Environment variables in Unix and Linux operating systems are used to store values that affect the way running processes will behave on a computer. The HOME environment variable, specifically, stores the path to the current user’s home directory.