CS151 Coursework  |  CS151 Home

Lab 1 is a self-guided set of exercises intended to increase your familiarity with the command line, subversion, and DrRacket. Even though you will commit a file to your subversion repository as part of this work, there is no official submission associated with Lab 1 and you will not be evaluated on it. You will be evaluated on all subsequent lab exercises.

Follow the steps below and ask questions as needed as you go along.

1.
  • Change to the root directory by typing cd /.
  • Type pwd and ls and have a look around.
  • Type cd with no arguments. Type pwd to see where you are.
  • Try cd .. and pwd.
  • Try cd - and pwd.
2.
  • Type cd with no arguments.
  • Type ls to see what's there.
  • Type ls -1 (that's the numeral 1) to display the contents of the working directory, one per line.
  • Notice the difference between the output of ls and the output of ls -F.
  • You can combine the effects of the options 1 and F in several ways: try ls -1 -F, ls -F -1, ls -1F and ls -F1.
  • Try ls -lFG.
  • There are many options to the ls command. Type man ls and read about some of them. Type q to exit man.
3.
  • Change to your home directory using cd. (From now on, any instructions that direct you to change directories mean you should use cd.)
  • Create a batch of empty files by typing touch file1.empty file2.empty file3.empty file4.empty file5.empty.
  • Type ls *.empty.
  • Type ls file*.
  • Type ls -lFG file*.
  • Type ls -hla file*.
  • Type rm file*.empty.
  • Type echo *.
  • Type echo *.*.
  • Type echo ~.
4.
  • Change to your home directory.
  • Create a batch of empty files by typing (note the capitals) touch FILE1.empty file2.empty FILE3.empty file4.empty FILE5.empty.
  • Type ls *.empty.
  • Type ls F*.empty.
  • Type ls f*.empty.
  • Type ls [Ff]*.empty.
  • Type ls [Ff].empty.
  • Type rm [Ff]*.empty.
  • Type ls *.empty.
5.
  • Change to your desktop.
  • Type for I in {1..500} ; do touch FILE$I.empty; done.
  • Look at the desktop. Take a moment to absorb what just happened.
  • Type ls FILE*.empty.
  • Type rm FILE*.empty.
6.
  • Type echo "a".
  • Type echo "b".
  • Type echo "c".
  • Type echo "a" > file1.file.
  • Type ls.
  • Type cat file1.file.
  • Type echo "b" >> file1.file.
  • Type ls.
  • Type cat file1.file.
  • Type echo "c" >> file1.file.
  • Type cat file1.file.
  • Type wc file1.file.
  • Type wc -l file1.file (that's a lowercase l as in, well, lowercase).
  • Type man wc and read a bit. Type q to exit man.
  • Type echo "d" > file1.file.
  • Type wc -l file1.file.
  • What happened?
  • Type cat file1.file.
  • Type rm file1.file.
7.
  • Type date.
  • Type NOW=`date` (those are backquotes).
  • Type echo NOW.
  • Type echo $NOW.
  • Type pwd.
  • Type CURRDIR=`pwd`.
  • Type echo CURRDIR.
  • Type echo $CURRDIR.
  • Type mkdir -p "$CURRDIR/banana".
  • Type B="$CURRDIR/banana".
  • Type echo $B.
  • Type cd $B.
  • Type cd ~.
  • Type pwd.
  • Type rmdir $B.
8.
  • Change to your desktop.
  • Check out a local copy of your repository with
    svn checkout https://phoenixforge.cs.uchicago.edu/svn/CNET-cs151-win-17
    but, when you do so, use your own actual CNet ID, not CNET.
  • At this point, if you don't have a subversion repository for some reason, please let the TA know, and continue with the exercises as best you can. You can circle back and do the subversion part of Lab 1 once your repository exists.
  • Type ls to make sure the local copy did indeed arrive.
  • Change into the local copy of your repository.
  • Type echo "This is a test." > test.file.
  • Type svn add test.file.
  • Type svn commit test.file -m "Adding a test file.".
  • Type svn mkdir lab1. This will create a directory lab1 inside your repository where you can store your lab 1 work.
9.

Start DrRacket.

DrRacket may at some point ask you to choose a "language level." For this exercise, select the "Beginning Student" level. When we start using Typed Racket you will select the "Determine language from source" option.

Type the following code into DrRacket's definitions pane:

9

(+ 9 1)

(+ 1 9)

(- 9 1)

(- 1 9)
Click the "Run" button at the top of the DrRacket window, and make sure you understand what you see.

Type the following code into DrRacket's definitions pane, under what you have already typed:

(* 9 1)

(* 1 9)

(/ 9 1)

(/ 1 9)
Click "Run" again.

Add these:

(expt 9 1)

(expt 9 2)

(expt 1 9)

(expt 2 9)

(+ (expt 9 1) 1)

(+ (expt 9 2) 2)

(- (expt 9 2) (expt 9 1))
Click "Run" again.

Now add these:

(= (expt 9 1) (expt 9 2))

(< (expt 9 1) (expt 9 2))

(> (expt 9 1) (expt 9 2))
Click the "Run" button again.

Finally, add these:

;; a : Integer
(define a 7)

;; b : Integer
(define b 8)

(* a b)

(- (* b b) (* a a))
"Run".

At this point, you should feel free to add, remove or modify any of the expressions of definitions in the definitions pane.

Save your lab1.rkt file in whatever state it's in. When you do so, make sure to save it in the lab1 folder you created in the previous step.

10.

To push your lab1.rkt file into your subversion repository, you need to add it first, then commit it. Note that once you've added a file, you do not need to add it again, although you will (usually) commit it again many times.

To do this, change into the root directory of your repository at the command line (you can use pwd to verify that you are in the correct directory). Then type these instructions:

  $ svn add lab1/lab1.rkt
  $ svn commit lab1 -m "committing lab1"
  

11.

You will now use Racket to render a crude illustration of a local landmark, the Sears Tower (which I refuse to call by its other name).

At the top of your lab1.rkt file, type

(require 2htdp/image)
Somewhere below — it doesn't matter where, exactly — type
(define sears-tower
  (above (beside (rectangle 2 11 "solid" "black")
                 (rectangle 3 1 "solid" "white")
                 (rectangle 2 11 "solid" "black"))
         (rectangle 10 30 "solid" "black")
         (rectangle 20 100 "solid" "black")))
After running, and hence registering this definition, you can view the illustration by typing sears-tower in the interactions pane.

Save the file. You don't need to add lab1.rkt to the repository again, because you've already done so. You do need to commit it again, though, and don't neglect the message (with -m "...") in your commit command.

12.

Getting out of trouble in the shell is a critical skill. Therefore, as the last exercise, we ask you to type some commands that will not succeed, to gain some experience with (minor) shell mishaps.

Try to determine the result of each of the following commands before typing them:

  $ cd ~
  $ ls foo
  $ mkdir foo
  $ ls foo
  $ touch foo/FILE1.empty
  $ ls foo
  
Explain (to yourself) the different results you observed typing the same command ls foo three times.

Now type this:

  $ rm FILE1.empty
  $ cd foo
  $ rm FILE1.empty
  $ ls foo
  $ cd ..
  $ ls foo
  
Why does one rm command fail and the other succeed?

Finally, try this sequence of instructions:

  $ touch foo/FILE1.empty
  $ ls foo
  $ rm FILE1.empty
  $ rm foo/FILE1.empty
  $ rmdir foo
  $ cd ..
  $ rmdir foo
  

This concludes Lab 1. You do not need to remove any files from the computer at which you have been working. If you're working at a Linux terminal, your files will stick around; if you're working at a Mac, be forewarned the CSIL Macs are wiped clean every night. Committing your work to your subversion repository should always serve as a comfort to you, that your work is safe and sound. See you in class!


Last revised: January 4, 2017