CSC 161 Grinnell College Fall, 2011
 
Imperative Problem Solving and Data Structures
 

Basic Linux Commands and Capabilities

Abstract

The original Unix operating system and its successor Linux were designed to support the common tasks and needs of computer users. This laboratory exercise reviews some basic commands and capabilities that match likely needs of CSC 161 students. The subsequent lab will continue on more Linux basics.

Introduction

This lab covers the capabilities and commands for a terminal window in the following table.

Topic Category Subtopics Linux Commands
Terminal Window open click on Desktop menu item
change password password
copying between windows left mouse button to highlight/copy; middle mouse button to paste
terminal utilities sleep, history, arrow keys, cat
autocompletion TAB
background process & operator at end of command
close control d

Before progressing further in this lab, be sure you have completed the readings for this lab.

The Terminal Window

For most of this lab, you will be experimenting with a terminal window.

Opening the Terminal Window

  1. You may already have a terminal window on screen. If not, start one by moving the pointer onto the small monitor icon on the bottom row of the front panel, and click with the left mouse button. If you do not have the terminal icon, speak with the instructor.

Changing Your Password

  1. Choose a new password. Make it something that you can easily remember, but not an English word or a name, since it is easy for system crackers to break in by guessing your password if you choose it from one of those categories.

    Use the password program within a terminal window to change your password.

Cutting and Pasting Between Windows

  1. Open the MediaScript console in addition to your Internet browser containing this lab.
    1. Consider the following Scheme procedure definition:

         (define mult5 
             (lambda (n)
                (* n 5)
             )
         )
      

      Select this material as follows: move the cursor to the beginning of a section and push down the left mouse button. Then, holding the button down, move the mouse to the end of the section. (The entire section now should be highlighted.) When the desired section is highlighted, stop pressing on the left mouse button — the section should stay highlighted.

      In preparation for later in this lab, save the resulting Definitions Window in MediaScript as the file my-test-file.

    2. Move the mouse to the definitions window of MediaScript, and click the middle mouse button to paste the definition into MediaScript.

    3. Can you paste this definition into both the MediaScript Interactions pane and a terminal window?

Terminal Utilities

This section asks you to practice with several useful commands within a terminal window.

Stopping a Long or Infinite Loop

  1. Within a terminal window, launch the sleep utility for 10 seconds:

       sleep 10
    

    Kill processing in the window with ctrl-c.

The Arrow Keys

  1. Move your mouse to a terminal window, and type several commands (e.g., use cat to display several Scheme programs you have saved during your previous CSC 151 course) and use the sleep command a few times. (This work creates a past record of work you have done in this terminal window.)

  2. Use the up-arrow key to retrieve several previous commands. Then, use the down-arrow to move to more recent commands.

  3. After you have retrieved the sleep 10 command, use the left-arrow key and then the delete key to edit the line to sleep 5. Then hit return and note what happens.

  4. Now use the up-arrow and left-arrow key to type a 1 before the 5 to produce sleep 15. (Do not use the right-arrow key to move the cursor to the end of the line.) Hit return, and use your watch to determine how long the sleep lasts. Note that you can edit any part of a line and then hit return to enter the entire line into the terminal window.

  5. Type history into the terminal window to get a list of recent commands you have issued in this terminal window.

  6. To re-issue a command, type an exclamation point followed by the command number from the history command. For example, suppose history gave you the list

      505  sleep 10
      506  history
    

    Then typing "!505" allows you to re-issue the sleep command.

    Now re-issue the history command in this way.

Background Processes

  1. Suppose you want to read the pdf file ~walker/c/examples/intro.pdf with the evince postscript/pdf reader.

    First, type

       evince ~walker/c/examples/intro.pdf
    

    This will open evince reader just fine, but now switch back to your terminal window. You will notice that it is unavailable for further use (i.e., you won't get another command prompt) until acrobat reader is closed.

    Now close evince reader, and then re-open it from the terminal window, but this time add an ampersand character to the end of the command:

       evince ~walker/c/examples/intro.pdf &
    

    Now when you return to your terminal window, a prompt is waiting for you, making it easy to do multiple tasks at once. Adding the ampersand character to a command causes the command to be launched as a "background process," allowing you to continue working with your terminal window.

Autocompletion

  1. Try using "autocompletion" with the file my-test-file by typing"cat ~/my-t" followed by a TAB key. You should find that when you press TAB the system completes the (unique) file name for you. Note that on the Campus Linux Network, when you type the tilde character "~" in the terminal window, the character will LOOK like a hyphen "-" instead. Even so, the system will interpret it as a tilde. (The command name cat stands for "concatenate" for reasons we will see later. It can be used to display the contents of a text file, so you should see the file my-test-file scroll by when you use this command.)

  2. Create a new file my-test-stuff using Dr. Scheme or another editor.

    What if you press TAB too early, such that there isn't a unique completion? Try this by typing cat ~/my-t, followed by TAB.
    Hit TAB a second time to see how the system responds.

    What happens if you type cat zqrz followed by TAB (where I am assuming you do NOT have a file zqrz)?

  3. Note that autocompletion also works with commands. For example, try typing his followed by TAB.
    What is the fewest characters you can type to produce the history command?
    What other commands begin with the letter h?
    Are there any commands that begin with her?

Closing a Terminal Window

  1. Try closing a terminal window by typing Ctrl/d

Reminder: Complete Evaluation Form

When you have finished this lab, be sure to fill out its evaluation form in the "Lab Evaluation" section for CSC 161 on Pioneer Web


This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~walker/courses/161.fa11/modules/module-getting-started/lab-linux-basics-1.shtml

created 31 March 2008 by Henry M. Walker
last full revision 18 July 2011 by Erik Opavsky and David Cowden
minor editing 22 August 2011 by Henry M. Walker
last revision 28 August 2011 by Henry M. Walker
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.