Lab 2: Command Line
For lab this week we'll be learning to utilize the command line, as illustrated briefly in class. Command line tools are available on all versions of the UNIX operating system (e.g Linux and Mac.)
For help on UNIX commands see:
Unix basic commands tutorial and command summary.
In particular be sure to learn ls, pwd, mkdir, cd, rmdir, pico to create a file, cp, mv, rm, lpr
UIC CS Department UNIX overview
Create a single text file containing the command used to do each of the Steps shown below. To begin editing a file, from the command line type in: pico labAnswers.txt
For instance your text file labAnswers.txt will look something like the following, however with different content on each line:
Dale Reed, Bart Simpson
reed, bsimp3
blah
la
di
da
words
go
here
pico ...
#include <...>
int main()
{
...
}
Ask
Questions
...
...
...
the last command
You should have two windows open, one for editing your text file, and a second for experimenting with the UNIX commands.
Steps:
List your name and that of your partner.
List your CS account name and that of your partner. If you don't have one, use your temporary account name. If you don't have either of those, talk to the TA. If you can't log on, find a partner that can and/or use a laptop. (If you don't have a partner, talk to the TA).
For each of the following steps you should figure out what the command is, then type that command in your text file.
List the files in the current directory.
Print the current working directory.
Navigate to the root directory. (This can be done with a single command, regardless of how many levels in you are.)
Navigate to your home directory. Again, this can be done in one command which should work regardless of which directory the terminal is currently in.
Create a directory named Lab2
Move into this newly created directory (Lab2) that you created in the previous step.
Move up one directory level (backing out of the directory Lab2).
Open a text editor to edit program lab2prog.c
Now move back into directory Lab2 (Hint: in most terminals you can use the up arrow key to cycle through previous commands).
Write a C program called lab2prog.c which outputs the following two lines:
Your names and CS account usernames
A statement of the form: I wish there was a program that _______.
(where you replace the ____ with some words of your own.)
Copy the contents of your program into the lab assignment.
Compile lab2prog.c using a C compiler on the command line.
Run the program.
Compile the program, calling the executable lab2prog rather than the default of a.out
By default, input comes from the keyboard and output goes to the screen. Changing this is known as redirection. See this page on how to redirect input and output using the < and > symbols.
Run the program, redirecting the output to file output.txt
Rename output.txt to Lab2output.txt
Compress folder Lab2 into a single tar or zip archive.
Submit your Solution
Submit only your textfile into Blackboard. If Blackboard is down then only one of you or your partner should email your textfile labAnswers.txt to your TA, where the title of the email is: 141 lab n solution where n is the time of day your lab starts. For instance if you are in the 2:00 lab, the title would be: 141 lab 2:00 solution
Points:
Note that for labs a grade of 2 is considered normal. Labs are designed so that few, if any, will get a grade of 3. If you get a grade of 2 on all of your labs, then you are on track to get an 'A' in this class.
With a partner complete steps 1-9 and submit the text file containing the command to execute each of those steps.
With a partner complete steps 1-12, and submit the text file containing the command to execute each of those steps, including the program for part 10.
With a partner complete steps 1-17, and submit only the text file to Blackboard.