Introduction to Linux

Linux Intro

Many of you are used to environments similar to Eclipse for code development (editing, compilation, and execution). In cmsc106 we we will perform the same tasks using the tools provided by the Linux operating system. Linux is a variation of Unix.

Logging on / Logging off to grace.umd.edu

Although you could install linux in your computer, we will rely on a computer system the university provides (grace.umd.edu). Anyone registered in this course will have an account on this system. The account id will be your directory id (e.g., terps) and the required password, your usual password. To access grace.umd.edu you need internet access and a program (ssh client) that will establish a connection between your computer and grace.umd.edu. Establishing a connection will create a window on your computer where you can execute commands.

Using an ssh client (see Logging on / Logging off to grace.umd.edu) log on to grace. When you log on you will land in the home directory (a directory is another name for folder). In this directory you can create files and directories. A prompt (e.g., grace2:~:) will appear after which you can execute commands. You execute commands by typing the command and pressing enter. To log out you can execute the logout command.

Commands

Linux has tons of commands, but we want to focus on the ones that will allow us to write and execute C programs.

Creating Files Using Editors

You can create files by using editors (e.g., emacs, vim) or other Unix commands. Initially we will use a simple text editor named nano, so we can focus on creating files.

To create a file using nano, type nano followed by a file name (e.g., nano p1.c). If the file already exists, the file will be opened, otherwise it will be created. Once you open a file, you will see at the bottom a commands summary. The ^ represents the CTRL key. Once you have opened the file, you can just start typing and use the arrow keys to move around. To save and exit execute ^X. At this point try creating a file with the following contents:

        #include <stdio.h>

        int main() {
            printf("I like Pepsi\n");

            return 0;
        }
    

Compilation

To compile a C program, you will use the gcc command. To compile the program p1.c you created earlier, execute the command gcc p1.c. If there are errors, you will see a listing of those errors; otherwise you will get the prompt back. If there are no errors, the compiler would have created a file called a.out. If you type a.out at the unix prompt, the program will be executed. The file a.out is overwritten each time you compile. It represents the machine language equivalent of the C program. Unlike Java programs where you compile to bytecode, and that bytecode can be executed by any java virtual machine, C code compiled for an environment will not necessarily work on others (you need to compile again). At this point you should compile p1.c and introduce errors to see the messages generated by the compiler.

Compiler Options

Several gcc compiler options are available that can provide additional warnings, generate code with different levels of effciency, etc. For example, gcc -Wall p1.c will provide additional warnings during compilation. For cmsc106 we have defined the options you need. To avoid having to type all those options each time you compile, you can create an alias for gcc. After you setup your account (see below) try setting the gcc alias. Information on how to set the alias can be found at setting gcc alias.

Setup Command for cmsc106

There is command (e.g., setup106) to configure your account so you can complete projects. This command will configure your account by:

  1. Creating the correct alias for the submit command that you will use to submit assignments.
  2. Create links to the directories where we place files you need and to the directory were you will develop your assignments.

If unfortunately you are repeating this course, you need to make sure you reset your Grace environment before you run the setup command. Please follow the instructions your previous instructor provided regarding resetting your Grace environment.

To run the setup command for cmsc106 spring 2023, copy and paste the following at the linux prompt, log out, and log on again. For other semesters, contact your instructor for the appropriate information. Notice thereis a one after summer in the below link (it is not a mistake) .

            /afs/glue.umd.edu/class/spring2023/cmsc/106/0101/public/bin/setup_106
    

The following changes would have taken place after executing the setup106 command:

Make sure you run the setup106 command and you set the gcc alias as described above. That is all the setup you need for the course. You will execute the setup106 command and set the alias only once.

Additional Commands

Start exploring linux commands by practicing the commands below. Make sure you are in your 106 directory.

File Transfer Utilities

Information available at File Transfer Utilities.

Resetting Your Grace Account

Once the semester is over, make sure you reset your Grace account/environment as described at Resetting Grace Environment

Web Accessibility