2. 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.
3. Linux commands
Create
a directory (folder): mkdir
[prompt] mkdir mydir
Change
[prompt] cd mydir
[prompt mydir]
Go
current directory: cd
up one directory: cd .. (note space)
[prompt mydir] cd ..
[prompt]
4. Commands, continued
Remove
[prompt] rmdir mydir
List
files/sub-directories: ls (letter ‘l’)
[prompt] ls
List
a directory (folder): rmdir
with details: ls -l
[prompt mydir] ls –l
5. Commands, continued
Copy
a file: cp
[prompt] cp origfile newfile
Rename
[prompt] mv origfile newfile
Remove
a file: mv
a file: rm
[prompt mydir] rm origfile
6. 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
7. 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
8. 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.
9. 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