Note If you do not finish today, you have until the begining of next class to submit this assignment
- More practice using the basic UNIX/Linux commands
- Practice using the emacs editor to modify an existing C program
- Make your working directory your home directory: type
cd
and pressreturn
- Verify your working directory is your home directory: type
pwd
and pressreturn
. - Steps 1 and 2 and the resulting output should look something like:
[robsz@linux3 ~] cd
[robsz@linux3 ~] pwd
/afs/umbc.edu/users/r/o/robsz/home
[robsz@linux3 ~]
- Make a new directory named
Personal
: typemkdir Personal
and pressreturn
- Make your working directory
Personal
: typecd Personal
and pressreturn
- Verify your working directory is
Personal
: typepwd
and pressreturn
- The last three steps and the resulting output should look something like:
[robsz@linux3 ~] mkdir Personal
[robsz@linux3 ~] cd Personal
[robsz@linux3 ~/Personal] pwd
/afs/umbc.edu/users/r/o/robsz/home/Personal
[robsz@linux3 ~]
- Use the
emacs
editor to create a file calledthings2do.txt
: typeemacs things2do.txt
and pressreturn
- Type the following contents in the buffer
1. Finish today's lab exercise.
2. Finish homework 1.
3. Bring my pet tarantula to CMSC104 for Show'n'Tell
- Exit the emacs editor, saving the file as you do so: press
Ctrl-X
followed byCtrl-C
followed byy
- Change your working directory to be one directory up from your current working directory: type
cd ..
and pressreturn
- Verify your current working directory is your home directory: type
pwd
and pressreturn
- The output from the last 5 steps should looks something like:
[robsz@linux3 ~/Personal] emacs things2do.txt
[robsz@linux3 ~/Personal] cd ..
[robsz@linux3 ~] pwd
/afs/umbc.edu/users/r/o/robsz/home
[robsz@linux3 ~]
- Start a transcript of your Unix session: type
script
and pressreturn
. The command and the resulting output should looks something like:
[robsz@linux3 ~] script
Script started, file is typescript
[robsz@linux3 ~]
- List the contents of the
Personal
directory: typels Personal
and pressreturn
- Print the contents of the file
things2do.txt
in thePersonal
directory on the screen: typecat Personal/things2do.txt
and pressreturn
- The output from the last 2 steps should look something like:
[robsz@linux3 ~] ls Personal
things2do.txt
[robsz@linux3 ~] cat Personal/things2do.txt
1. Finish today's lab exercise.
2. Finish homework 1.
3. Bring my pet tarantula to CMSC104 for Show'n'Tell
[robsz@linux3 ~]
- Create a directory called
PersonalBackup
: typemkdir PersonalBackup
and pressreturn
- Verify that it exists by listing the contents of your current working directory: type
ls
and pressreturn
- Copy the file
things2do.txt
fromPersonal
toPersonaBackup
: typecp Personal/things2do.txt PersonalBackup
and pressreturn
- List the contents of the
PersonalBackup
directory: typels PersonalBackup
and pressreturn
- The output of the last 4 steps should look something like:
[robsz@linux3 ~] mkdir PersonalBackup
[robsz@linux3 ~] ls
bin cs104 Desktop Documents Downloads introtoc Music Personal PersonalBackup Pictures Public Templates typescript Videos
[robsz@linux3 ~] cp Personal/things2do.txt PersonalBackup
[robsz@linux3 ~] ls PersonalBackup
things2do.txt
[robsz@linux3 ~]
- Attempt to delete the
Personal
directory: typermdir Personal
and pressreturn
. The command and resulting output should looks something like:
[robsz@linux3 ~] rmdir Personal
rmdir: failed to remove `Personal': Directory not empty
[robsz@linux3 ~]
- You cannot remove a non-empty directory. You must first delete its contents. Delete the
things2do.txt
file in thePersonal
directory: typerm Personal/things2do.txt
and pressreturn
then pressy
to confirm - Verify it is gone by listing the contents of
Personal
: typels Personal
and pressreturn
- Remove the
Personal
directory: typermdir Personal
and pressreturn
- The output from the last 3 steps should looks something like:
[robsz@linux3 ~] rm Personal/things2do.txt
rm: remove regular file `Personal/things2do.txt'? y
[robsz@linux3 ~] ls
bin cs104 Desktop Documents Downloads introtoc Music Personal PersonalBackup Pictures Public Templates typescript Videos
[robsz@linux3 ~] rmdir Personal
[robsz@linux3 ~]
- Move
things2do.txt
from thePersonalBackup
directory to your current working directory: typemv PersonalBackup/things2do.txt .
and pressreturn
- Verify file is in your current working directory by listing the current working directory contents: type
ls
and pressreturn
- The output from the last 2 commands should looks something like:
[robsz@linux3 ~] mv PersonalBackup/things2do.txt .
[robsz@linux3 ~] ls
bin cs104 Desktop Documents Downloads introtoc Music PersonalBackup Pictures Public Templates things2do.txt typescript Videos
[robsz@linux3 ~]
- Exit the script session: type
exit
and pressreturn
. The command and resulting output should look something like:
[robsz@linux3 ~] exit
exit
Script done, file is typescript
[robsz@linux3 ~]
- Verify that you have a file called
typescript
in your current working directory: typels
and pressreturn
- Submit the
typescript
file: typesubmit cs104_kdruffel cw02 typescript
and pressreturn
- The output from last two commands should looks something like:
[robsz@linux3 ~] ls
bin cs104 Desktop Documents Downloads introtoc Music PersonalBackup Pictures Public Templates things2do.txt typescript Videos
[robsz@linux3 ~] submit cs104_kdruffel cw02 typescript
Submitting typescript...OK
[robsz@linux3 ~]
Write a C program that prints out "Hello, world!" twenty times, using a new line each time.
- Make your current working directory the
introtoc
directory that we created as a sub directory of your home directory in the last class: typecd ~/introtoc
and pressreturn
- If the directory is missing (because you were absent, etc) then make your current working directory your home directory: type
cd
and pressreturn
- Open the file
hello.c
for editing inemacs
: typeemacs hello.c
- The contents of your buffer should look like:
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
- If the contents of your buffer do not look like the above, make it so.
- Use the cut and paste feature of
emacs
to edit the contents of the buffer so that your program will print the required line 20 times. - Exit
emacs
, saving your work. PressCtrl-X
then pressCtrl-C
then pressy
- Start a sript session: type
script
and pressreturn
- Print the contents of
hello.c
to the screen: typecat hello.c
and pressreturn
- Compile your program: type
gcc hello.c
and pressreturn
- Run your program: type
./a.out
and pressreturn
- Exit the script session: type
exit
and pressreturn
- Rename your
typescript
file totypescript2
: typemv typescript typescript2
and pressreturn
- Submit your
typescript2
andhello.c
files: typesubmit cs104_kdruffel cw02 hello.c typescript2
and press return - Log out of gl: type
exit
and pressreturn