Homework 1

Due: Wednesday, January 19, at 11:00pm

This assignments asks you to exercise basic bash commands and activities. Students will submit via Gradescope, and may re-submit after viewing the intial auto-grading output. The goal is to ensure that every student has some fundamental shell skills.

This assignment will not teach you all the commands you many need to complete this course. You should use the Linux Pocket Guide and the Linux man command or the online version of the Linux man pages to find specific commands needed to answer these questions. Use the Pocket Guide to read about related commands and topics.

Google is also useful for locating things, but you need to learn your way around the Guide and the standard Linux documentation, which should be your primary source. Beware that some answers returned by Google are misleading, so use it for more finding the correct direction than for the entire solution.

Requirement Specifications

For this assignment you must use either your account on the cancun.cs.washington.edu machine or your own copy of the CSE Linux Virtual Machine (VM). This will enable the autograder to evaluate your work, as well as give you more experience on those systems. See the Linux Resources page on the course web site for more information about these systems.

NOTES: Sections are highlighted below for ease of reading only. Please be patient with the autograder - we will review all points lost but that will take a little time.

  1. Enter script hw1.script to start recording your work.
  2. Make a new directory called HW1
  3. Change directories to that directory
  4. Display your current working directory

  5. Run a command to print "This is fun!" to the screen.
  6. Run the above command and redirect the output to a file called now
  7. Run a command to print the current date and time and append the output to now
  8. Run a command to print the kernel version and append it to now

  9. Your now file should have three lines in it. Use the wc command to display the number of lines (and only the number of lines) in the file.
  10. Show the contents of the now file

  11. There is, on bash, a file called alias. Enter a command to figure out where this file is.
    • There are a number of ways to find or locate a file on a Linux system, and more then one way to solve this problem. Remember you can use man -k to figure out the name of a command you don't yet know.
    • These methods have some differences and are not entirely interchangeable. It is worth understanding the differences.
    • The autograder will accept a few, but probably not all, solutions.
  12. Copy the file you found into your current directory.
    • Hint: You want the file without any extensions on the name. It should be a readable text file.
  13. Rename (move) the file to myalias
  14. List the contents of your directory. Use the option that shows the additional details (permissions, date edited, etc.) about each file.

  15. The previous command will show that myalias currently has permissions set to be executable by all users. Enter a command to reset the permissions to read & write for the user, and read only for the group and all.

  16. Enter vi myalias to open the file in vi.
  17. Exit vi
    • Knowing how to exit vi is useful!
  18. Enter emacs myalias top open the file in emacs.

  19. Edit your file while in emacs (or you could do this in vi if you wish, and then just start and exit emacs)
  20. Save your file and exit emacs. You should be back in your shell.
  21. Enter a command to change your shell environment to include the new alias
  22. Demonstrate your new alias by entering ll

  23. Enter emacs to start emacs
  24. Use ctrl-z to suspend emacs
  25. Bring emacs back to the foreground. Then ctrl-z again.

  26. Enter a command to list all the processes belonging to your user
  27. Since this might be a lot of processes, re-enter the command and pipe the output through grep to find the phrase "emacs"
  28. Terminate this process by using a command at your bash prompt

  29. And, last, but not least, use echo, and the existing environment variable USERNAME to print user rocks!, with you as the user, to the screen.
    • Hint: Your environment variable may be USER instead of USERNAME
    • Hint: You can see all the current environment variables by entering printenv, or the value in one variable by entering echo "$VARNAME"
    • My screen says: mh75 rocks!
  30. Enter exit to stop recording your script.

Assessment

This assignment is worth 40 points. (1-2pts per step above.) There will be an autograder, and you are welcome to resubmit your assignment until you get a perfect score (or until the due date).

Hint 0: It is likely worth while going through the assignment twice. The first time work out what to do at each step. You can use all the resources at your disposal, including lectures and demos, man files, and google.Remember that you can also use the history command to look at all the commands you have executed - this may help you review your work in preparation for a second run through that you record for submission.

Hint 1: The scriptcommand records everything, even backspaces. If you have too many corrections there will be a lot of extraneous characters if your hw1.script file that may interfere with the autograder. In this case, repeat the exercise carefully avoiding extra key strokes.

Hint 2: There are usually multiple ways to accomplish a task on Linux, and there are many ways you could accomplish the steps for this assignment. If you use one that is too esoteric the autograder will not give you credit. In this situation you should try using something more straight-forward. If you still feel that the autograder is incorrect, please ask the staff to look at it.

Turning In

Please submit to the Gradescope HW1 assignment. This is linked through Canvas, or you can go directly through Gradescope. You should submit one file, called hw1.script.