Solution to Lab 0 4.1 "Try it Out":

In the examples below, $ is the shell prompt, and anything after # is a comment with some additional information about the command.

  1. cd into your home directory. Then use pwd and ls to "see" where you are, and to list a directory’s contents.

    $ cd            # cd with no argument goes to your home directory
    $ pwd           # should list /home/yourusername/
    $ ls
  2. Copy the file from ~admin21/public/welcome.txt into your home directory using the cp command.

    The cp command takes two command line arguments: the path name of the source file to copy; and the path name of the destination file (cp source dest). We show two different ways to specify the source and destination file for this operation.

    $ cp ~admin21/public/welcome.txt welcome.txt

    Here is another way of doing this using ./ which is shorthand for the current directory The syntax below copies from the source to current location:

    $ cp ~admin21/public/welcome.txt ./
  3. Run ls to see if your copy was successful.

    $ ls
      welcome.txt
  4. Use cat to list the contents of the welcome.txt file.

    $ cat welcome.txt
      Welcome to CS21!
      ...
  5. If you have successfully run update21 then try this:

    1. List the contents of your cs21/ directory.

      $ cd                          # cd into your home directory
      $ ls cs21                     # list contents of your cs21 subidrectory
        for_staff/  inclass/  labs/
    2. Use cd to move into your cs21/inclass directory. Use pwd to "see" where you are.

      $ cd cs21/inclass
      $ pwd
        /home/yourusername/cs21/inclass
    3. Use cp to copy the welcome.txt file from your home directory into your cs21/inclass directory. Use ls to see if the file was successful copied.

      The cp and mv commands takes two command line arguments: the path name of the source file to copy/move, and the path name of the destination file (cp source dest). We show three different ways to specify the source and destination file for this operation.

      Here is one way to do it. I’m naming the destination file welcome.txt in this example, but I could also change its name to something else:

      $ cp /home/yourusername/welcome.txt welcome.txt

      Here is another way to do it using some shorthand notation. ~/ is shorthand for /home/yourusername/, and ./ is shorthand for the current working directory. The syntax below moves the file from your home directory (~/) into the current directory (./):

      $ cp ~/welcome.txt ./

      Here is yet another way to do it. The path ../ is shorthand for the parent directory of the current directory, so ../../ is the parent of the parent of cs21/inclass/, which is your home directory.

      $ cp ../../welcome.txt ./