CSC 161 Grinnell College Spring, 2010
Imperative Problem Solving and Data Structures

More Basic Linux Commands and Capabilities


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
Terminal Window open  
change password password
copying between windows  
terminal utilities sleep, history, arrow keys, cat
background process  
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
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.

The Terminal Window

As with the previous lab, most work for this lab involves experimentation with a terminal window.

Directory and File Commands

The Linux Directory/File Hierarchy

In this section, we will explore part of the Linux file hierarchy.


  1. In a terminal window, type pwd (print working directory) to determine the absolute path name of the current directory.

  2. 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.

  3. 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.

  4. 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:

    root directory hierarchy
  5. Use the commands which and whereis to locate where the evince program is located:

       which evince
       whereis evince

Search Paths

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.

  1. Within a terminal window, type the command

         echo $PATH

    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 (:).

    1. Write down the listing of directories that are searched when you enter a command into a Linux window. For example, what directory is searched first?
    2. Consider the echo command. Use the ls command to determine if an echo program is located in the first directory on the path. If not, look at the second directory, etc., until you find where ls is located.
    3. Examine the search path printed to determine if the current directory (represented as .) is listed. If the current directory is NOT in your search path, it will be helpful later in the course if we add . to your search path.

      To add . to your search path, open your .bashrc file in any editor and add the following lines:
      # Debian Linux does not appear to include the current directory in the
      # search path, so we'll expand the search path:
      PATH = $PATH:.

File Utilities

Consult the following commands in completing the next steps of this lab.

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)
  1. 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.

  2. Move to the labs subdirectory within your csc161 directory. Then move to your sup-prob directory with the command

      pushd ../sup-prob

    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

Displaying Text Files

  1. 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.

The Manual

  1. Use the man to consult the online Linux manual:

    1. What do the following command options mean?

        cp -p
        ls -ltrF
        mkdir -p
    2. Why does the cat command have the name "cat", which stands for "concatenate"?

    3. 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.

  2. 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 --sides=duplex file
prints file to default printer (handles many standard file formats)
same, but double-sided
displays jobs in print queue on default printer
lprm 585
cancels (removes) print job number 585 from default printer queue

Directory and File Permissions

The following steps ask you to review the permissions for your account directories and adjust them for this course.

  1. Move to your home directory and obtain a "long" listing of the files present using the commands:

       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.

  2. 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!

Setting Permissions

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.

  1. 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.

  2. Now suppose you set your home directory with the command

       chmod 711 ~
    1. Can others obtain a listing of your home directory?
    2. Can others obtain a listing of your labs subdirectory?

Setting Terminal Defaults

  1. Review the material present in the .bashrc file in your home directory. Be sure you can explain the purpose of the umask and alias commands.

This document is available on the World Wide Web as

created 31 March 2008
last revised 9 January 2010
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at