Introduction to Linux, Pico, G++

9
CS111 Lab Linux etc. Instructor: Michael Gordon

description

 

Transcript of Introduction to Linux, Pico, G++

Page 1: Introduction to Linux, Pico, G++

CS111 Lab Linux etc.

Instructor: Michael Gordon

Page 2: Introduction to Linux, Pico, G++

Linux

We will be using the Linux OS, which

may be different from the operating

systems you have used before

(Windows, Mac OS).

There is no GUI or mouse-interface.

Commands are typed at the prompt.

Page 3: Introduction to Linux, Pico, G++

Linux commands

Create a directory (folder): mkdir

[prompt] mkdir mydir

Change current directory: cd

[prompt] cd mydir

[prompt mydir]

Go up one directory: cd .. (note space)

[prompt mydir] cd ..

[prompt]

Page 4: Introduction to Linux, Pico, G++

Commands, continued

Remove a directory (folder): rmdir

[prompt] rmdir mydir

List files/sub-directories: ls (letter ‘l’)

[prompt] ls

List with details: ls -l

[prompt mydir] ls –l

Page 5: Introduction to Linux, Pico, G++

Commands, continued

Copy a file: cp

[prompt] cp origfile newfile

Rename a file: mv

[prompt] mv origfile newfile

Remove a file: rm

[prompt mydir] rm origfile

Page 6: Introduction to Linux, Pico, G++

Pico

Pico is a text editor for Unix. In this lab we

will use it to write our C++ code.

To open or create a file in pico:

[prompt] pico filename.cpp

To save: Control+o (letter ‘o’) prompts you

to overwrite. ‘Enter’ for ‘Yes’. Or change

the file name.

To exit pico: Control+x

Page 7: Introduction to Linux, Pico, G++

In Pico

In Pico we will write our C++ code.

Note: You must move your cursor with the

arrows keys, not the mouse.

To ‘cut’ a line of code, use Control+k

To ‘paste’ use Control+u

Page 8: Introduction to Linux, Pico, G++

Compiling

Once you’ve written a C++ program, you

need to compile it (translate it into

machine code) before running it.

We use a compiler called g++.

[prompt] g++ file.cpp

An executable file is automatically

created (or overwritten) with the name

a.out.

Page 9: Introduction to Linux, Pico, G++

Executing

To run the executable file, type:

[prompt] ./a.out

To give a name to your .out file:

[prompt] g++ -o name.out file.cpp

To run:

[prompt] ./name.out