| CSC 161 | Grinnell College | Spring, 2012 |
| Imperative Problem Solving and Data Structures | ||
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.
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 | |
| manual | man | |
| close | control d | |
| Help | manual | man |
Before progressing further in this lab, be sure you have completed the readings for this lab.
For most of this lab, you will be experimenting with a terminal window.
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.
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.
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.
Move the mouse to the definitions window of MediaScript, and click the middle mouse button to paste the definition into MediaScript.
Can you paste this definition into both the MediaScript Interactions pane and a terminal window?
This section asks you to practice with several useful commands within a terminal window.
Within a terminal window, launch the sleep utility for 10 seconds:
sleep 10
Kill processing in the window with ctrl-c.
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.)
Use the up-arrow key to retrieve several previous commands. Then, use the down-arrow to move to more recent commands.
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.
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.
Type history into the terminal window to get a list of recent commands you have issued in this terminal window.
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.
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.
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.)
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)?
Note that autocompletion also works with commands.
Try typing his followed by TAB.
What is the fewest number of 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?
Use the man command to consult the online Linux manual (Note the q key is used to exit man pages):
What do the following command options mean? Note the ability to smash flags together.
cp -p ls -ltrF mkdir -p
Why does the cat command have the name "cat", which stands for "concatenate"?
Use the man page for the C function sqrt to identify the parameters and return type for a collection of functions related to sqrt. Also, what "include" statement is needed for sqrt
The command man -k keyword lists commands that seem related to the given keyword. For example, to print a list of man pages that include the word "square" in the name or description fields, you could use "man -k square". Try this command to locate sqrt and to determine various commands related to the keyword "print".
Try closing a terminal window by typing Ctrl/d
Development of laboratory exercises is an iterative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.