| CSC 153 | Grinnell College | Spring, 2009 |
| Computer Science Fundamentals | ||
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 beginning CSC 153 students.
This lab covers the following basic capabilities and commands.
| Topic Category | Subtopics | Linux Commands |
|---|---|---|
| Terminal Window | open | |
| change password | password | |
| copying between windows | ||
| terminal utilities | sleep, history, arrow keys, cat | |
| background process | ||
| autocompletion | ||
| close | ||
| Directories and Files | paths | ., .., ~, /, pwd |
| pathnames | absolute, relative, pwd, cd, ls, which, whereis | |
| file utilities | mkdir, rmdir, rm, cp, mv, more, head, tail, pushd, popd | |
| Help | manual | man |
| Printing | printing | lpr, a2ps, lpq, lprm |
| Permissions | user, group, world | ls -l |
| setting permissions | chmod | |
| start up | .bashrc, .bash_profile, umask, alias |
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.
Set the window aside for the moment (e.g., minimize the window) by clicking on the small bar or underscore character at the upper right-hand corner of the window, and restore the window by moving the pointer onto its icon and clicking the left mouse button.
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 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 Dr. Scheme as the file my-test-file.
Move the mouse to the definitions window of Dr. Scheme, and click the middle mouse button to paste the definition into Dr. Scheme.
Can you paste this definition into Dr.Scheme's Interactions window and into 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 previous CSC 153 labs) 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.
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. 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?
Suppose you want to read the pdf file ~walker/c/examples/examples.pdf with the acrobat reader.
First, type
acroread ~walker/c/examples/examples.pdf
or use autocompletion to reduce your typing! This will open acrobat 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 acrobat reader, and then re-open it from the terminal window, but this time add an ampersand character to the end of the command:
acroread ~walker/c/examples/examples.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.
Close your terminal window with the keyboard shortcut ctrl-d.
In this section, we will explore part of the Linux file hierarchy.
In a terminal window, type pwd (print working directory) to determine the absolute path name of the current directory.
Type ls . to get a listing of the current directory, and ls .. to get a listing of all files in the parent directory. Note that your current directory should be visible as one item within its parent directory.
The tilde character used alone specifies your home directory, so ls ~ will give a listing of your home directory. When the tilde appears before a name, the combination denotes the home directory before the home directory corresponding to the name. Thus, ls ~walker lists the home directory for user walker.
The top of the Linux file hierarchy is designated by a slash (/) and is called root. Use the command ls / to obtain a listing of all files and directories within the root directory. How many are there?
In reviewing the files within the root directory, look at the following specific directories:
/bin: These are the executable programs that comprise the GNU/Linux utilities. For example, there is an executable file here named ls that is run when you issue the command ls.
/home: You won't be surprised to hear that user accounts are stored in this directory.
/lib: This directory is the home of many libraries that can be used by programmers. For example, you should be able to find a file named libc-2.3.6.so here, that contains the "standard c library functions" we will use later in the course.
/usr: The name of this directory is pronounced "user", and it generally contains application programs, libraries, and other files that are not part of the GNU/Linux system (i.e., optional resources intended for and requested by users). For example, the acrobat reader is located here under /usr/bin/acroread.
Use the commands which and whereis to locate where the acroread program is located:
which acroread whereis acroread
Consult the following commands in completing the following steps.
| Utility | Description |
| ls | "list" files and directories |
| pwd | "print working directory" |
| cd | "change (your working) directory" |
| mkdir | "make directory" |
| rmdir | "remove directory" |
| cp | "copy" a file or directory |
| mv | "move" a file or directory (i.e., rename it) |
| rm | "remove" a file (i.e., delete it) |
Within your home directory, create a new directory csc153. Then move to this csc153 directory and create subdirectories scheme, c, labs, and sup-prob.
Move any CSC 153 files from your home directory to the relevant subdirectory of csc153. As the semester progresses, this organization will help you keep your various files separate.
Move to the labs subdirectory within your csc153 directory. The move to your sup-prob directory with the command
pushd ../sup-prob
Check that the command popd takes you back to the sup-prob subdirectory.
Write a few sentences that explain the difference between the following commands:
pushd ../scheme cd ../scheme
Try the following commands that display all or part of this laboratory exercise:
cat /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml more /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml less /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml head /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml head -n 20 /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml tail /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml tail -n 20 /home/walker/public_html/courses/153.sp09/labs/lab-linux-basics.shtml
(Note that this is a wonderful time to use the arrow keys to edit previous commands rather than to retype the full lines each time.) For the less command, try the arrow keys to move up and down in the file.
Use the man to consult the online Linux manual:
What do the following command options mean?
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 identifyIt the parameters, return type, and "include files" needed for a set of functions related to 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".
In the interests of saving paper, this lab does not ask you to practice printing files with the lpr and a2ps commands. However, you should review the following table for future reference.
| Utility | Description |
| a2ps file a2ps -Pescher file a2ps --sides=duplex file |
prints file to default printer (handles many standard file
formats) same, for printer named escher same, but double-sided |
| lpq lpq -Pescher |
displays jobs in print queue on default printer same, for printer named escher |
| lprm 585 lprm -Pescher 585 |
cancels (removes) print job number 585 from default printer queue same, for printer named escher |
The following steps ask you to review the permissions for your account directories and adjust them for this course.
Move to your home directory and obtain a "long" listing of the files present using the commands:
cd ls -l
(The cd command without parameters takes you to your home directory.)
Interpret the meaning of each part of the directory and file listings.
Just for fun, type the whoami command as a type of reassurance that you still are still functioning logically — even with the length of this lab!
For CSC 153, it seems likely that you will want others in the class to be able to read your labs, since you are collaborating with others on that material. However, you do not want others to be able to read your supplemental problems. These steps set up this framework.
Move to your home directory. Then allow others to read (but not change) your login directory with the command:
chmod 755 .
Next allow others to read (but not change) files in your labs directory:
chmod 755 labs
Now use the ls -l -a command to check that others can read your home directory and the labs subdirectory, but no other directories.
Team up with another class member to check which directories of theirs you can read.
Now suppose you set your home directory with the command
chmod 711 ~
This document is available on the World Wide Web as
http://www.cs.grinnell.edu/~walker/courses/153.sp09/labs/lab-linux-basics.shtml
|
created 31 March 2008 last revised 7 April 2008 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |