Compiling and running C/C++ programs on Unix/Linux

To compile and run programs on Linux you have first to login into your account in linux.uwsuper.edu with your login and password provided by the instructor.

  1. To compile your programis use the following instructions:
    gcc filename.c for C programs
    g++ filename.cpp for C++ programs

    If the compilation is successful you will see no warnings on the screen. Just a new prompt appears in the line following the compilation instruction. If the compiler finds an error, the number of the line in your source file containing the error will be displayed.

  2. After successful compilation of your program by using the g++ command you will get file a.out in the same directory. In order to run it enter
    ./a.out

    Alternatively, to create an executable file with a specific name, use the g++ instruction with the "-o" key:

    gcc filename.c -o filename2 for C programs
    g++ filename.cpp -o filename2 for C++ programs

    In this case executable file filename2 will be created and can be executed by entering

    ./filename2

    If your program hangs up type Ctrl-C to terminate it.

Some useful Unix/Linux commands

Unix as well as Windows is an operating system, and a number of very convenient text editors and window managers are designed for it. However, since we use just a remote access to Linux machine via ssh that is not designed to exchange graphical information from the Linux screen, we have to type in all the necessary commands.

Shell commandsComments
ls
cd Mydir
mkdir dir_name
rmdir dir_name
rm file_name
cp old_file new_file
mv ol_file new_file
vi file_name
joe file_name
nedit filename
less filename
list files in current directory
go to subfolder Mydir
make new folder dir
delete (empty only) folder dir
delete file file_name
copy old_file to new_file
rename old_file to new_file
edit file with vi editor
edit file with joe editor
edit file with nedit editor (in graphics mode only)
open file only for reading

For more information refer to Linux tutorial for beginners