|CSC 161||Grinnell College||Spring, 2010|
|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.
This lab continues work with the following basic capabilities and commands.
|Topic Category||Subtopics||Linux Commands|
|copying between windows|
|terminal utilities||sleep, history, arrow keys, cat|
|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|
|Permissions||user, group, world||ls -l|
|start up||.bashrc, .bash_profile, umask, alias|
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
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.) 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.
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|
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 161, 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
created 31 March 2008
last revised 9 January 2010
|For more information, please contact Henry M. Walker at email@example.com.|