UNB/ CS/ David Bremner/ teaching/ old/ cs2023/ events/ Tutorial Exercise 1

Prerequisites.

See the lab guide for information about physical and login access to the lab.

Security

Make sure that you log out again whenever you are done with a machine. If you are seated at a lab machine, there is a logout option on the “System” menu. If you are logged in remotely via ssh, then use the "exit" or "logout" commands.

Exercises

  1. While at a computer in the lab, open a terminal window. There may be an icon in the task bar at the top that you can click to do this, or you should be able to find it in the menus at “Applications->Accessories”. All the commands in these exercises should be typed in this command window.

  2. Identify your current directory with the command pwd, which displays the “current working directory” of the shell process. This is the directory used for all relative file names. Now make a subdirectory named cs2023 for this course using the mkdir command. Change the shell's current directory to this new directory using the cd command. Now create a new subdirectory for this tutorial called tutorial1 and change to that directory. Identify the current directory using pwd. Run this command again, directing its results to a text file named ques2.txt with the command pwd > ques2.txt.

  3. Identify the system that you are on by typing the command uname -a in the command window. Rerun this command directing the output to ques3.txt.

  4. Make a subdirectory of cs2023/tutorial1 named ques4 and change to that directory.

  5. Copy the file /fcs/courses/cs2023/tutorial1/hello.c to this directory. Examine the file using cat hello.c. Also examine the file using “less”. You get out of less using the one letter command “q” (for “quit”).

  6. Compile this “C” program using “cc hello.c”. Examine the result with “ls”. Note that the file “a.out” was created. Run the resulting file with “./a.out”. Run this again, directing it's output to the file ques4.txt in this directory.

  7. Change to the parent directory (“..”) and make a new directory ques5. Then change to the new directory.

  8. Choose a text editor. The requirement is that the editor produce standard Unix text files, i.e. lines of ASCII text, each ended by the Unix “new line” character (technically ASCII LF, also called “line feed”). Some possible editors that run in a command line and therefore are useable via “ssh” are “vi” and “emacs”. Because you are presently at the console keyboard and display of a lab Linux machine, you could also use the Gnome text editor gedit, available from the menus at “Applications->Accessories->Text Editor”.

  9. Create a single C source file (in the ques5 subdirectory) containing the example dweight2.c from page 23 of the course text.

  10. Compile and run this program

  11. Make a tar file of the ques5 directory.

    • Rename the ques5 directory to ques5.bak using the mv command. Check the man page using man mv if you need a hint.

    • Extract your tarfile to recreate the ques5 directory