PRACTICE: Homework 1

Due: Friday, October 13, at 11:59pm

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 your account on seaside.cs.washington.edu. This ensure that you have some experience with remote connections, as well as enable the autograder to evaluate your work. See the Linux Resources page on the course web site for more information about connecting to Seaside.

NOTES: Sections are highlighted below for ease of reading only. The autograder will be looking for you to execute a specific set of commands.

Setup: We want to use drive space (memory) that can be accessed from many different machines. This will allow you flexibility with what machine you use at any given time, while retaining access to your files. We accomplish this by making sure we've mounted the udrive, and are working in that drive.

  1. While in ~/ mount the drive by typing mntclassdir cse374
  2. Start working in that directory cd cse374
This process allows you to use your udrive space as a regular linux directory. You can also access this space in a variety of other methods. UW's instructions are here.

Please note that you may not need to use mntclassdir every time you log in, but you'll want to make sure you are working in the cse374 directory within your udrive.

Assignment Steps

  1. Make sure you are in your cse374 directory.
  2. Enter script hw1.script to start recording a transcript of your work.
  3. Make a new directory called HW1
  4. Change directories to that directory
  5. Display your current working directory

  6. Run a command to print Linux is great to the screen.
  7. Run the above command and redirect the output to a file called now
  8. Run a command to print the current date and time and append the output to now
  9. Run a command to print the kernel release and append it to now

  10. 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.
  11. Show the contents of the now file
    • There are many commands to do this. The commands have subtle differences.
    • The autograder will recognize a few straight-forward, but probably not all, options.
  12. Copy the now file to a file called pastnow

  13. Go to your home directory, and then enter a command to locate the pastnow file in your folders.
    • 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.

  14. Move to the directory with now in it
  15. List the contents of that directory. Use the option that shows the additional details (permissions, date edited, etc.) about each file.
  16. Enter a command to reset the permissions for the now file to read, write & execute for the user, and read & execute only for the group and read only for other. You should do this in one step.
    • Hint: The command from 13 will show you if you got it right! Do that NOW.

  17. Return to your home directory
  18. Enter vi .bashrc to open the bash resources file in vi.
  19. Exit vi
    • Knowing how to exit vi is useful!
  20. Enter emacs .bashrc to open the file in emacs.

  21. Edit your file while in emacs (or you could do this in vi if you wish, and then just start and exit emacs)
    • You will add to this file, but not remove anything that is already in it.
    • Add a line to define an alias that allows you to type ll and execute the command you used in step 13
  22. Save your file and exit emacs. You should be back in your shell.
  23. Enter a command to change your shell environment to include the new alias
  24. Demonstrate your new alias by entering ll

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

  28. Enter a command to list all the processes belonging to your user
  29. Since this might be a lot of processes, re-enter the command and pipe the output through grep to find the phrase "emacs"
  30. Terminate this process by using a command at your bash prompt
    • You will need to send a signal '-9', or otherwise specify 'kill' the process.

  31. And, last, but not least, use echo, and the existing environment variable USER to print user is great, with you as the user, to the screen.
    • Note: Your environment variable may be USERNAME instead of USER - use the applicable one
    • 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 is great
  32. 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. You will likely want to move your file from Seaside to your local machine, and use the web interface for Gradescope. In order to accomplish this you can use scp: scp @seaside.cs.washington.edu:~/udrive/cse374/HW1/hw1.script ./ This will move your file to whatever directory you are in when you use it. In the future you can also access files on your udrive as linked above, or use vscode to move files, but it is definitely worth getting scp to work a few times so you know how to use it.