Homework 1: Bash Practice
Due: Friday, April 10, at 11:59pm
Background and Specifications
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.
Web searches and AI are also useful for locating things, but you should learn your way around standard Linux documentation (man pages) which are the definitive reference. Beware that some answers returned by Googlein a web search are misleading, so use it for more finding the correct direction than for the entire solution.
Background
For this assignment you must use your account on calgary.cs.washington.edu. This ensures 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 Calgary.
NOTES: Sections are highlighted below for ease of reading only. The autograder will be looking for you to execute a specific set of commands. This time we tell you what to do and it is up to you to find the correct commands.
Exercise Specifications
- Make sure you are in your cse374 directory. (You made one in HW0, remember?)
- Enter
script hw1.scriptto start recording a transcript of your work. - Make a new directory called
HW1 - Change directories to that directory
- Display your current working directory
- Run a command to print
Linux is the bestto the screen. - Run the above command and redirect the output to a file called
now - Run a command to print the current date and time and append the output to
now - Run a command to print the system node-name and append it to
now - Your
nowfile should have three lines in it. Use thewccommand to display the number of lines (and only the number of lines and the file name) in the file. - Show the contents of the
nowfile - 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.
- Copy the
nowfile to a file calledpastnow - Go to your home directory, and then enter a command to locate the
pastnowfile 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 -kto 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.
- Move to the directory with
nowin it - List the contents of that directory. Use the option that shows the additional details (permissions, date edited, etc.) about each file.
- Enter a command to reset the permissions for the
nowfile 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.
- Return to your home directory
- Enter
vi .bashrcto open the bash resources file in vi. - Exit vi
- Knowing how to exit vi is useful!
- Enter
emacs .bashrcto open the file in emacs. - 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
lland execute the command you used in step 13 - Save your file and exit emacs. You should be back in your shell.
- Enter a command to change your shell environment to include the new alias
- Demonstrate your new alias by entering
ll - Enter
emacsto start emacs - Use
ctrl-zto suspend emacs - Bring emacs back to the foreground. Then
ctrl-zagain. - Enter a command to list all the processes belonging to your user
- Since this might be a lot of processes, re-enter the command and pipe the output through
grepto find the phrase "emacs" - 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.
- And, last, but not least, use
echo, and the existing environment variableUSERto printuser 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 enteringecho "$VARNAME" - My screen says:
mh75 is great - Enter
exitto stop recording your script. - You'll have to enter
exitagain to stop working on Calgary.
Submit your homework
Please submit to the Gradescope HW1 assignment. This is linked through Canvas, or you can go directly through Gradescope. scp This will move your file to whatever directory you are in when you use it.
Grading
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
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.