|CSC 161||Grinnell College||Fall, 2011|
|Imperative Problem Solving and Data Structures|
This laboratory exercise continues the previous lab to review basic commands and capabilities that match likely needs of beginning CSC 161 students. In the subsequent lab, you will learn a few more basic commands and also prepare for compiling programs for use with the robots.
This lab continues work with the following basic capabilities and commands.
|Topic Category||Subtopics||Linux Commands|
|Directories and Files||paths||., .., ~, /, pwd|
|pathnames||absolute, relative, pwd, cd, ls, which, whereis|
|search paths||search path variable $PATH|
|file utilities||mkdir, rmdir, rm, cp, mv, more, head, tail, pushd, popd|
|Printing||printing||lpr, a2ps, lpq, lprm|
Before progressing further in this lab, be sure you have completed the readings for this lab.
As with the previous lab, most work for this lab involves experimentation with a terminal window.
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/evince.
Use the commands which and whereis to locate where the evince program is located:
which evince whereis evince
What is the difference between the two commands?
The system sets up many elements for you when you log in, and additional set up may occur whenever you open a window. For example, the operating system processes a file called .bashrc in your home directory each time it opens a terminal window.
One of these elements is an environmental variable $PATH that indicates where the operating system should look for various commands.
Within a terminal window, type the command
Examine the output of this command to determine where the operating system looks for various commands and in what order. Within this string, directories are separated by colons (:).
# Debian Linux does not appear to include the current directory in the # search path, so we'll expand the search path: PATH=$PATH:.
Consult the following commands in completing the next steps of this lab.
|ls||"list" files and directories|
|pwd||"print working directory"|
|cd||"change (your working) 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 csc161. Then move to this csc161 directory and create subdirectories scheme, c, labs, and sup-prob.
Move any CSC 161 files from your home directory to the relevant subdirectory of csc161. As the semester progresses, this organization will help you keep your various files separate.
Move to the labs subdirectory within your csc161 directory. Then move to your sup-prob directory with the command:
Check that the command popd takes you back to the labs subdirectory you were in before your change to sup-prob.
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/161.sp09/labs/lab-linux-basics-2.shtml more /home/walker/public_html/courses/161.sp09/labs/lab-linux-basics-2.shtml less /home/walker/public_html/courses/161.sp09/labs/lab-linux-basics-2.shtml head /home/walker/public_html/courses/161.sp09/labs/lab-linux-basics-2.shtml head -n 20 /home/walker/public_html/courses/161.sp09/labs/lab-linux-basics-2.shtml tail /home/walker/public_html/courses/161.sp09/labs/lab-linux-basics-2.shtml tail -n 20 /home/walker/public_html/courses/161.sp09/labs/lab-linux-basics-2.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. You can also use the tab autocomplete utility.)
For the less command, try the arrow keys to move up and down in the file.
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".
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.
a2ps --sides=duplex file
|prints file to default printer (handles many standard file
same, but double-sided
|lpq||displays jobs in print queue on default printer|
|lprm 585||cancels (removes) print job number 585 from default printer queue|
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
created 31 March 2008 by Henry M. Walker
last full revision 18 July 2011 by Erik Opavsky and David Cowden
minor editing 24 August 2011 by Henry M. Walker
last revised 30 August 2011 by Henry M. Walker
|For more information, please contact Henry M. Walker at firstname.lastname@example.org.|