<<

System Programming, Homework Assignment 1 Due Wednesday, January 20

Playing around on Earth

For this assignment, you will get a chance to get used to using the command-line interface offered by the shell and using your chosen text editor. Even if you have a machine of your own, you will need to complete this assignment on one of the department’s general-purpose Unix systems (e.g., earth). Notice that I’m not asking you to turn in anything for this work. I’ll take a look in your account on Wednesday to see if you’ve done these tasks. Also, at the start of class on Wednesday, we’ll have a short quiz to see how much you’ve learned about your text editor. Log on to the Unix systems using putty, or some other secure shell client. If this is your first time using these systems, change your password using the passwd command. When your account was created, it was assigned a randomly-generated password. You will want to change this to something that’s easy for you to remember but hard for anyone else to guess. Just type the passwd command at the shell prompt. This will prompt you for your old password and give you a chance to choose a new password. This change will automatically alter your password on all of our Unix machines. There is a similar command, chsh, that will change your default shell command. A number of alternative shells are available for people who prefer a slightly different command-line interface. For now, let’s all stay with the default shell your account was created with (bash). You may want to look into using a different shell after the semester is over.

Meet your Editor

Getting familiar with your text editor is one of the most useful things you can do right now. Work through the tutorial for your chosen editor. This will only take about half an hour and it will help you become familiar with some of its basic commands.

• For , run vimtutor from the command prompt • For , run emacs and then type C-h t (Ctrl-t then t)

Write a Bash Profile

Use your text editor to make a file named .bash profile in your home directory. This file contains com- mands that are run automatically every time you log in to the system with a bash shell. This file will be your first simple shell script. Put in some shell code to print out a welcome message when you log in, report the date/time and then set your shell prompt to something of your choosing. Your shell prompt is stored in an environment variable, PS1. You can set it with syntax like: PS1="your-new-prompt" Be careful. If you make a bad enough mistake in your .bash profile, it may prevent you from being able to log in at all. While editing your .bash profile, you will want to log in to the system more than once at the same time. You can use one login to edit .bash profile (we’ll call this your edit ) and another to log in and out to test your new profile. Don’t log out of your edit window until you are sure you have a profile that’s good. If you break something and it prevents you from logging in, you will still have your edit window open to fix whatever you broke.

1 Getting Around in the Filesystem

After class, I will create a 3336 s10/a1 directory in the home directory of your Unix filesystem. Look around the directories and subdirectories in 3336 s10/a1. You have to perform a few operations on files in these directories. Do the operations in this order, since there is some interdependency.

1. First, find the file named busy work.txt. You may have to look around a little bit for it; it’s in one of the subdirectories. Open this file with your chosen text editor and follow the instructions in the file. Write out the modified file when you’re done.

2. In the stuff directory, there is one file that contains the word delete. Please delete this file. Remember, you can see what a file contains by opening it with your favorite text editor or by printing it out to the screen using cat. 3. Go into the more stuff directory. Make a subdirectory called duplicates, and copy from the stuff directory to the duplicates directory all files ending in .txt.

4. Somewhere in the directory tree, you will find a C source file named run cat.c. This file is supposed to be a working C program, but it contains a few obvious errors. Use your text editor to fix these errors and then compile the resulting executable in the same directory. The following command can be used to compile a source file called “work.c” and produce and executable named “work”. Use a similar command to compile cat.c to an executable named cat.

cc -o work work.c

5. Run the cat file you just compiled, and send its output to a file called output.txt in the same directory. Running cat will be a little tricky since it has the same name as a common shell command. If you just type “cat”, you will run the cat shell command. To run your program, you will have to use a path rather than just the name of the executable.

6. Find the file named -remove-me and delete it. Notice that this file will be a little tricky to delete since it’s name starts with a dash.

7. Hidden files start with a dot. These are not usually shown by ls, but there is an option for ls that will show all files. Find the one hidden file in the directory tree and rename it to the same name without the starting dot. 8. See who’s on the system while you’re working and save this output into a file called “3336 s10/a1/things/users.txt”. You can do this by redirecting the output of the who command.

2