CS 270
Lab 0 - Checkin and Linux Tutorial
Objectives of this Lab
- login to department systems,
- login to the Canvas course,
- learn how to launch Linux applications,
- introduce a small set of Linux commands,
- discuss the Linux file system and play with text files.
- write your "Hello World" program in C
Logging In
- Login to the machine using your electronic ID (same username that you use for RamWeb).
- The initial password should be your student ID number (same as nine digit number on your RamCard).
- Choose "Xfce session" from the list of linux configurations in the upper right hand corner of the screen.
- Click "Use default configuration" when the pop-up message comes up (first log-in only).
- The teaching assistant will show you how to change your password as described below.
- Troubleshooting: Raise your hand if you cannot login!
Class Website
- Start your preferred internet browser and type in your course URL
- www.cs.colostate.edu/~cs270
- Note that semester that appears as part of the url!
- Look at the syllabus and progress pages.
- Open another tab and in the url type http://info.canvas.colostate.edu/login.aspx
- Login to Canvas using your EID and password and make sure you can see this course.
Launching Applications
- Your TA will show you how to launch applications and add them to the task bar.
- Select "Activities" in the upper left corner of the screen, then select "Applications".
- Run firefox, kate, file manager, and a terminal.
- The terminal command brings up a window where you can type in Linux commands.
- Note: this is similar to using the DOS command prompt on Windows.
- Use the
passwd
command to change your password.
- We recommend changing it to your RamWeb password, if possible.
Useful Terminal Commands
Your TA will show you how to use the man command. For each of the following, figure out what action is performed and try the command. Be careful with the remove command!
- man - read the manual page for a command
- pwd - print working directory
- ls - list working directory
- cd - change working directory
- cp - copy file(s)
- mv - move or rename file(s)
- rm - remove file(s)
- cat - list file(s)
- less - list file(s)
- diff - compare files
- mkdir - make directory
Your TA will talk about launching programs from a terminal using the amperand (&), and will show you how to look at the history of commands, and how auto completetion with the tab key works.
Linux File System
Your TA will describe the Linux file system. Make sure you know each of the following shortcuts for directory names:
- ~ home directory
- . current directory
- .. parent directory
- / file extensions
Manipulating Text Files
Perform the following tasks and add to your notes to show the TA:
- Create a directory in your home directory called cs270
- Use gedit to create the Name.txt:
gedit Name.txt &
- The file should contain one line which has your first and last name.
- Save the file .
- Copy Name.txt to another file called Name.bak
- Compare the contents of the files by using the diff command. Are they the same? How can you tell?
- Open Name.bak as a second tab in gedit.
- Add a second line to Name.bak with your preferred email address.
- Compare the files again. Are they the same? How can you tell?
- Remove Name.txt
- Move Name.bak to Name.txt
- Cat the contents of Name.txt. Is your email there?
Hello World
- In your cs270 directory, create an R0 directory
- Using gedit, create the file hello.c with the following content:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
- Copy the file below into your R0 directory
cp ~cs270/Current/recitations/R0/src/Makefile .
- Run the Makefile by typing in "make".
- Run the executable by typing in "hello".
- Check the file hello.c into the checkin server
- Verify it passed all the tests
Makefiles
In this case, we used make to compile our program. When we execute
make, it searches for the file named Makefile in our
current working directory and executes the code. Makefiles are declarative,
meaning that instead of having a set of instructions that get executed in order,
you more or less just define the relationship between parts of the program. Your
TA will walk through this basic Makefile with you.
In this example, typing 'make' is equivalent to the following:
gcc -g -Wall -o hello hello.c
However, we can build makefiles to do much more complicated compilations,
especially for larger, multifile projects. When you use a makefile,
you don't have to manually compile everything, or build long commands.
Makefiles have one further advantage- what happens if you type make again
to compile hello.c? Because the hello.c file hasn't been modified, the makefile
doesn't do anything. 'make' will only compile if something has changed about the
program, which can save time when you're trying to compile a large project.
This Makefile has another rule which we can manually execute by typing 'make clean'
in the terminal. The 'clean' rule is a very common Makefile rule that removes everything
generated by the makefile. I.e., 'clean' will undo everything the makefile has done.
Notice that this simply uses a 'rm' command. Although Makefiles are typically used
for compilation, they aren't limited to compilation.
VIM
VIM is an advanced text editor that has many helpful features for fast
editing of text from the console. Its predecessor VI has a very similar
interface and in some cases, such as when working on older systems or striped
down VM's, it may be the only tool you have to edit text. Use the rest of
the time to work through the VIM tutorial which can be accessed by typing:
vimtutor
Although VIM has a steep learning curve, when utilized at it's full potential,
it can be much quicker than a text editor. At the bare minimum, you should be
passable at using VIM.