Information about the use of C in Linux

Document Sample
Information about the use of C in Linux Powered By Docstoc
					Information about the use of C in Linux
Linux is an operating system, just like Windows.

Login on Linux
login: <US number> password: student

To change your password
Type the following in the console: passwd

To change directories in Linux
Type the following in the console: cd <directory name>

To make a directory in Linux
Type the following in the console: mkdir <directory name>

To remove a directory
Non-empty directories cannot be removed. Files and subdirectories must be removed first. To remove an empty directory, type the following in the console: rmdir <directory name>

To delete a file
Type the following in the console: rm <file name>

To copy a file to disk
Change to the directory the file is in and type the following in the console: mcopy <file name> a:}

To copy a from disk
Change to the directory where you want the file and type the following in the console: mcopy a:\ <file name>

To see what is on a disk
Type the following in the console: mdir a:

1

To log out
Click on the icon with the big K on it and then on Logout.

How to use Kate
You will find kate very easy to work with. Save your program files with extension .c and the highlight mode will be set to C. There is also a terminal tab so that you do not need to leave the program to compile your code.

To open Kate
Click on the Start Application icon (the one with the big K on it).

To save a new file
Click File, Save As and type the file name.

To open an existing file
Click File, Open.

To save a file that already has a name
Click File, Save.

To go to a specific line number
Click Edit, Go to Line and type in the line number.

To manually set highlight mode
Click Tools, Highlighting, Sources, C This will make it easier to program as you can see clearly when you have made a mistake.

2

To compile a C program
The easy way
In a terminal, like the Konsole program or in the terminal tab in Kate, type: gcc <filename.c> -o <exeName> If you leave out the -o <exeName> part, gcc will name your executable a.out.

The advanced way
Note: This is not necessary for the purpose of this course, but is handy to know for your course, later in the year. Type in the following in a new file in Kate and save it as makefile with no extension. In place of <file name> type the name of the file you are working with. #-------------------------------------------# This is THE great magnificent GMA makefile #-------------------------------------------LIBS = -I /usr/include -L./ -lm #--------------------SRCS = <file name>.c OBJS = <file name>.o #--------------------FLAGS = DEBUG = CFLAGS = DEBU G CC = gcc #−−−−−−−−−−−−−−−−−−−−− all : clean<f ilename> @echoDone clean : @>err #−−−−−−−−−−−−−−−−−−−−− <f ilename>:OBJS $CC -o <file name> OBJSLIBS

3

Make sure that it is stored in the same directory as the file you wish to compile. To compile your file, in the console, (the icon with a shell in it) change to the directory that you are working in. Then type make. This will make an object file of your program. An object file is a file which the computer can understand and execute. To run you program, type ./<file name> in the console. To change your makefile quickly, open it and use Edit, Replace to replace the old file name with the new!

4


				
DOCUMENT INFO
Shared By:
Stats:
views:6
posted:12/16/2009
language:English
pages:4
Description: Information about the use of C in Linux