# Access the Command Line ## Dennis Kibbe ### Mesa Community College Note: This slide presentation was created using Reveal.js. You can access a transcript of this presentation by pressing S for speaker notes. You can access navigation help by pressing the question mark key. Audio for this presentation is artificially generated. --- # Module Outline 1. Introduction 1. Access the Command Line 1. Access the Command Line with the Desktop 1. Execute Commands with the Bash Shell 1. Key Takeaways 1. Resources 1. Graded Lab Note: --- # Learning Objectives *After successfully completing the work in this module you will be able to:* 1. Log into the GNOME Desktop and run commands in a Bash shell. 1. Log into a text-based host and enter commands. 1. Use Bash shell features to save time entering commands. 1. Troubleshoot common mistakes when entering commands. Note: --- # Introduction ## Access the Command Line ![image showing thew relationship of the shell to the Linux kernel](../images/kernel_shell_utils.png) Note: Far from being obsolete, the command line is the most efficient way of managing a Linux server. Graphical interfaces while pretty, are slow, difficult to automate, and use resources without contributing to a server's mission. In this course you'll learn to use the Bash shell like a pro. --- # The GNOME Terminal Program ![The GNOME terminal program](../images/gnome_terminal-1.png) Note: The GNOME Desktop is the graphical interface used by many Linux distributions. The GNOME Terminal is the program you will use to complete most of the labs in this course. When you first open the terminal you will see the shell prompt with some important information such as who you are on the system, the name of the host you are logged into, and your current directory. The dollar sign ends the prompt and indicates that you are an unprivileged user. (The correct pronunciation of GNOME is with a hard G.) --- # Log in Using the Text Console ![image of a text-based login screen](../images/text_console.png) Note: When you type the password at a text prompt no characters will show unlike a graphical login you may be used to. Type the exit command to log out of the console. Only Workstation has a graphical login screen. --- # Log in Using Secure Shell ![image of a SSH login screen](../images/ssh_remote.png) Note: For most of the labs in this course you will log into `servera` and `serverb` using Secure Shell or SSH. Secure Shell creates a secure, encrypted connection between hosts on an insecure network like the Internet. Note that the prompt has changed to show that student is now logged into `servera`. --- # Log Out Using Secure Shell ![image of a SSH log out screen](../images/ssh_remote_exit.png) Note: To close the connection to a remote host type the `exit` command. Note that the prompt shows that user student has returned to workstation. --- # The Lab Environment ![the lab environment](../images/lab_env.png) Note: The Lab Environment lets you open a console for `servera` or `serverb` to log in without using a network connection. Think of the console as a backdoor to fix network connection issues. Be sure to watch the video on the Lab Environment page. --- # Quiz ## Access the Command Line ![clipboard](../images/clipboard-check.png) Note: After reading this section in the textbook complete the quiz in Canvas. --- # Access the Command Line with the Desktop Note: Most of the time in this course you will access a remote host using a terminal program on the GNOME Desktop. --- # Access the Command Line with the Desktop ![The GNOME Desktop](../images/gnome_desktop.png) Note: If you don’t see the terminal icon at the bottom of the screen click the Activities button at the left end of the taskbar and type ”terminal” to start the terminal application. --- # The Shell Prompt ![The GNOME terminal program](../images/gnome_terminal.png) Note: The shell prompt contains much useful information. In this example, User student is logged into workstation. The current directory is student’s home directory. --- # Quiz ## Access the Command Line with the Desktop ![clipboard](../images/clipboard-check.png) Note: After reading this section in the textbook complete the quiz in Canvas. --- # Guided Exercise ## Access the Command Line with the Desktop ![Clipart of two students studying](../images/homework.png) Note: In this exercise, you log in through the graphical display manager as a regular user to become familiar with the GNOME Standard desktop environment. Be sure to check the assignment in Canvas before starting the assignment for any lab notes. --- # Execute Commands with the Bash Shell Note: --- # The Bourne Again SHell ![Bash shell](../images/bash.png) Note: The Bash or Bourne Again SHell is the default command interpreter used by most Linux distributions. --- # Entering Commands ![Entering commands](../images/bash_command.png) Note: The shell waits for your instructions. Linux is a case-sensitive operating system and almost all commands are lower case. Some commands such as the `ls` command used to list files can be run without any options or arguments. Other commands like the `mkdir` command must have an argument. Here the `ls` command is showing the files in the current directory which is student’s home directory. Sub-directories are shown in blue and ordinary files in black. You can change how the terminal looks by making the text larger, selecting a light or dark theme, and even create your own custom look using the hamburger menu. --- # Modifying a Command with an Option ![a command with an option](../images/bash_command_option.png) Note: Options for commands start with a single dash and must be separated from the command by a space. Here the `-a` option lists all the files in student’s home directory including hidden files and directories which start with a period. --- # Adding an Argument to a Command ![Fixme](../images/bash_command_option_argument.png) Note: Adding a directory name as an argument to the `ls` command lists files in the hidden `.ssh` directory. The `-l` option lists the files in a long format which includes additional information such as permissions, ownership, file size, and modification or creation date. --- # Tab Completion ![a command with an argument](../images/tab_completion.png) Note: Tab Completion is a powerful feature of the Bash shell and will save you time and frustration. Tab Completion can automatically complete commands, options, and file names. This example demonstrates how Tab Completion can help in changing the current directory to the Documents directory. After typing the first letter of the directory name and then pressing the Tab key nothing happens because there is more than one possible completion. Pressing the Tab key a second time narrows the selection to Desktop, Documents, or Downloads directories. As additional characters are typed the selection narrows until there is only one possible completion. --- # Write a Long Command on Multiple Lines ``` [student@serverb ~]$ touch \ ~/Documents/project_plans/{season1,season2}_project_plan.odf ``` Note: Some lab instructions include the \ (backslash) character at the end of a line. This indicates that the command continues on the next line. I suggest not typing the backslash and continue typing the remainder of the command on the same line. Note that commands you type are in a bold typeface in the instructions. --- # Bash History ![Bash history](../images/history.png) Note: The Bash shell keeps a list of the commands you run. You can re-run any command in the list by typing an exclamation point which is called a bang in UNIX speak followed by the number of the command. For example, to run the `ls Desktop` command again type an exclamation point followed by 4. --- # Troubleshoot Errors Entering Commands Note: The shell can be unforgiving and you will make mistakes. Recognizing errors and knowing how to deal with common errors will accelerate your mastery of the shell. --- # No Such File or Directory ![Error message when file is not found](../images/no_such_file.png) Note: This error message means exactly what it says. The ls command could not list the file you asked for. --- # Troubleshoot "No Such File or Directory" ![Using the ls command to troubleshoot.](../images/no_such_file-2.png) Note: When you get this error check the prompt to see if you are in the directory where the file was created, then run the `ls` command to see if the file was misspelled or is capitalized differently. You can often avoid this error by using Tab Completion wherever possible to automatically complete file names. --- # Incomplete Commands ![incomplete mkdir command](../images/incomplete_command.png) Note: If the command you typed is missing a required option or argument the shell will return a short help message or, sometimes, the complete manual page for the command. In this example the `mkdir` command requires a directory name as an argument. --- # Unfinished Commands ![Unfinished Commands](../images/incomplete_command-2.png) Note: The Bash shell knows that this command is not finished and opens a subshell so you can complete the command by adding the missing quote. --- # Troubleshoot Unfinished Commands ![Unfinished Commands](../images/incomplete_command-3.png) Note: Typng the missing trailing quote and then pressing Enter finishes the command so the shell can run it. --- # Unresponsive Commands ![The terminal is unresponsive.](../images/hung_command.png) Note: Some commands will simply hang if not entered correctly. Here the `cat` command was entered without the required file name and blocks any further access to the command prompt. Here a required argument was not given to the `cat` command which is now unresponsive. --- # Troubleshoot Unresponsive Commands ![Image showing how to end a unresponsive command.](../images/hung_command-2.png) Note: Press **Ctrl** plus **c** to interrupt the command and return the shell prompt. --- # Graded Quiz ## Execute Commands with the Bash Shell ![clipboard](../images/clipboard-check.png) Note: After reading this section in the textbook complete the quiz in Canvas. --- # Graded Lab ## Access the Command Line ![Screenshot of a sample grading script](../images/lab_grade_example.png) Note: In this lab, you use the Bash shell to execute commands. When you complete the lab submit a screenshot of the output of the `lab grade cli-review` command. The screenshot shown here is for reference only. --- # Key Takeaways 1. The Bash shell is the standard command interpreter on most Linux systems. 1. Many commands have a `--help` option. 1. Using the GNOME Desktop you can have multiple Workspaces to organize tasks. 1. The *Activities* button shows an overview of open windows and applications. 1. The `file` command is used to identify a file's type. 1. The `head` and `tail` commands display the first 10 lines or the last 10 lines of a file. 1. Tab completion automatically completes commands, options, and file or directory names. 1. To save resources most Linux servers only have a text interface. 1. A backslash (\\) at the end of a line means that the command continues on the next line. Note: --- # Resources - [Resources Introducing the GNOME 3 Desktop](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/desktop_migration_and_administration_guide/introducing-gnome3-desktop) - [Useful GNOME keyboard shortcuts](https://help.gnome.org/users/gnome-help/stable/shell-keyboard-shortcuts.html.en) - [The `history` command](https://www.networkworld.com/video/86695/2-minute-linux-tip-learn-how-to-use-the-history-command) - [The `head` and `tail` commands](https://www.youtube.com/watch?v=zyQkUAj-3g8&feature=youtu.be) - [The `ls` command](https://www.infoworld.com/video/101239/how-to-use-the-ls-command-2-minute-linux-tips) - [The `wc` command](https://youtu.be/7bdp3b3JCdY) - [The `touch`](https://youtu.be/8vy9iVVqPrw) - [The `--help` option ](https://youtu.be/fldFuvPgL5Q) - [How to use the `pwd` command: 2-Minute Linux Tips](https://youtu.be/bBM_flm2Ths) - [How to use tabs for autocompletion: 2-Minute Linux Tips](https://youtu.be/MC0ghMuL1NM) - [How to use the `date` command: 2-Minute Linux Tips](https://youtu.be/4Ci0IWX1_s4) - [How to move around the Linux command line: 2-Minute Linux Tips](https://www.networkworld.com/video/663070/how-to-move-around-the-linux-command-line.html) - [How to use Ctrl-r to rerun prior commands: 2-Minute Linux Tips](https://www.networkworld.com/video/663069/how-to-use-ctrl-r-to-rerun-prior-commands.html) - [How to use the more and less commands: 2-Minute Linux Tips](https://www.networkworld.com/video/663146/how-to-use-the-more-and-less-commands-2-minute-linux-tips.html) - [How to use the head and tail commands: 2-Minute Linux Tips](https://www.networkworld.com/video/663148/how-to-use-the-head-and-tail-commands-2-minute-linux-tips.html) Note: Here are some resources to help you with this module. --- ![Mesa Community College logo](../images/mcc_logo.png "Mesa Community College") Note: This is the end of this slide presentation.