Classwork 2: More Unix Practice
Objectives
More practice using the basic UNIX/Linux commands
Note: at the end of the lab, you will use submit to turn in a transcript of your Linux session. If you do not finish all the steps, just submit as much as you get done.
Assignment 1
- Move to your home directory. Make sure you are there (
pwd
). - Create a new directory named
Personal
. Verify that the directory exists. - Move to the
Personal
directory. Verify that you are there. - Use the nano editor to create a file called
things2do.txt
.linux1[32]% nano things2do.txt
Once you have opened the file, you should type the following:
1. Finish today's lab exercise. 2. Finish homework 1. 3. Bring my pet tarantula to CMSC104 for Show'n'Tell
Save the file and exit nano (use Ctrl-X).
- Move back to your home directory. Verify that you are
there.
- Start a transcript of your Unix session with
linux1[33]% script Script started, file is typescript
- List the contents of the
Personal
directory (ls Personal
). It should contain only the filethings2do.txt
. - Display the contents of
things2do.txt
on the monitor (cat Personal/things2do.txt
ORmore Personal/things2do.txt
ORless Personal/things2do.txt
). To exit out of less, you should type 'q'. - Make sure you are in your home directory! Create another subdirectory
called
PersonalBackup
in your home directory. Verify that it exists. Both Personal and PersonalBackup should be in your home directory. -
linux1[34]% pwd /afs/umbc.edu/users/p/a/park/home/ linux1[35]% mkdir PersonalBackup linux1[36]% ls cs104 Mail bin www Personal PersonalBackup linux1[37]%
Copy the file
things2do.txt
fromPersonal
toPersonalBackup
.linux1[38]% cp Personal/things2do.txt PersonalBackup linux1[39]%
Look at the contents of the
PersonalBackup
subdirectory. It should now contain the filethings2do.txt
. - Try to delete the
Personal
subdirectory. You will get a message that the directory is not empty. You must delete all files and subdirectories from a directory before deleting the directory itself. So,- Delete
things2do.txt
fromPersonal
. - Look at the contents of
Personal
to make sure that it is empty. - Delete the
Personal
subdirectory. - Look at the contents of your current (home) directory to make
sure that
Personal
has been deleted.linux1[40]% rmdir Personal/ rmdir: `Personal/': Directory not empty linux1[41]% rm Personal/things2do.txt rm: remove regular file `Personal/things2do.txt'? y linux1[42]% ls Personal/ linux1[43]% rmdir Personal linux1[44]% ls cs104 Mail PersonalBackup bin www linux1[45]%
- Delete
- Move
things2do.txt
from thePersonalBackup
directory to your current (home) directory.linux1[46]% mv PersonalBackup/things2do.txt . linux1[47]% ls cs104 Mail PersonalBackup bin things2do.txt www linux1[48]%
- Look at the contents of your home directory to be sure that
things2do.txt
is there. - Look at the contents of
PersonalBackup
to be sure thatthings2do.txt
is no longer there. - Delete the
PersonalBackup
subdirectory. - Delete
things2do.txt
.
- Look at the contents of your home directory to be sure that
-
Now you have to stop recording the transcript of your Unix session:
linux1[49]% exit exit Script done, file is typescript
- Check that you have a file named typescript.
- Check that the file is not empty using cat.
linux1[49]% submit cs104_chang cw02 typescript
Assignment 2
Write a C program that prints out "I will not chew gum in class" twenty times.
- Use nano to edit a file called gum.c. Note that the filenames of C programs must end with .c.
- Use the following "Hello World" program as a template
except print out "I will not chew gum in class" instead of
"Hello World"
#include <stdio.h> int main() { printf("Hello World\n") ; return 0 ; }
- Use the cut-and-paste feature of nano to cut the line that prints out "I will not chew gum in class" and paste it back in. (Use ctrl-K to cut and ctrl-U to paste.)
- Save the file and exit nano.
- Start a script session:
linux1% script
- Use cat to display your program:
linux1% cat gum.c
- Compile your program using gcc:
linux1% gcc -Wall gum.c
- Use ls to make sure that you have a file called a.out.
- Run your program:
linux1% ./a.out
- Quit your script session:
linux1% exit
- Look at your typescript file to make
sure it is correct:
linux1% cat typescript
- Rename your typescript file to typescript2:
linux1% mv typescript typescript2
- Submit your C program and the typescript file:
linux1% submit cs104_chang cw02 gum.c typescript2
Be sure to logout completely when you have finished!