600.120 Intermediate Programming, Spring 2017 Misha Kazhdan
Outline Unix/Linux command line Basics of the Emacs editor Compiling and running a simple C program Cloning a repository
Connecting to ugrad On lab computer or your Windows laptop Open PuTTy and connect to ugrad: Open connection with hostname ugradx.cs.jhu.edu Mac: open Terminal application and type: ssh <username>@ugradx.cs.jhu.edu ugradx.cs.jhu.edu
Unix / Linux Powerful class of operating systems Multiuser, unified file system Command-line interface text-based commands, no graphical user interface (GUI) allow for easy automation of series of commands
Unix / Linux When you login, you will be in your home directory. pwd: prints the name of the current directory ls: prints the contents of the current directory cd <(sub-)directory name>: changes the current directory to the specified (sub-)directory cd..: go up one directory (a single. indicates current directory) cd /: go to the root directory cd ~: go to the home directory mkdir <directory name>: create a new directory within the current directory
Unix / Linux cp <source> <target>: copy the source to the target mv <source> <target>: move the source to the target more <file-name>: displays the contents of a file, one screen at a time less<file-name>: a more powerful version of more emacs [<file-name>]*: my text editor of choice *feel free to use a different editor (e.g. VIM) if you prefer
Emacs Basics Can type directly Arrows move you around Basics [CTRL]-x + [CTRL]-c: quit [CTRL]-x + [CTRL]-s: save [CTRL]-x + [CTRL]-f: open a file* [CTRL]-x + u: undo [CTRL]-_: undo [CTRL]-g: cancel *prompts show up at the bottom
Emacs Basics Cut / Paste: [CTRL]-k: [CTRL]-[SPACE]: [CTRL]-w: [ESCAPE]+w: [CTRL]-y: Search / Replace: [CTRL]-s: [ESCAPE]-%: kill the rest of the line set (start) mark cut from the mark to the cursor copy from the mark to the cursor copy the previously cut/copied buffer search forward* query replace* And much much more: [ESCAPE]+<command name>:...
Coding Flow Editor main.c Compiler a.out Source file (human readable) Binary executable (machine readable)
Coding Flow Editor main.c Compiler a.out 1. Write code (e.g. in Emacs) #include <stdio.h> // Print "Hello, world! followed by newline and exit int main( void ) { printf( "Hello, world!\n ); return 0; }
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out.
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out. gcc: use the GNU C compiler
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out. gcc: use the GNU C compiler -std=c99: use the C99 standard
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out. gcc: use the GNU C compiler -std=c99: use the C99 standard -pedantic: use the strict ANSI standard
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out. gcc: use the GNU C compiler -std=c99: use the C99 standard -pedantic: use the strict ANSI standard -Wall: enable all warnings
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out. gcc: use the GNU C compiler -std=c99: use the C99 standard -pedantic: use the strict ANSI standard -Wall: enable all warnings -Wextra: enable still more warnings
Coding Flow Editor main.c Compiler a.out 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c This generates the executable a.out. gcc: use the GNU C compiler -std=c99: use the C99 standard -pedantic: use the strict ANSI standard -Wall: enable all warnings -Wextra: enable still more warnings main.c: the source file (with a main function).
Coding Flow Editor main.c Compiler hello 2. Compile the code into an executable >> gcc -std=c99 -pedantic -Wall -Wextra main.c o hello If you want the executable to have a different name: -o hello: specifies the output to be hello
Coding Flow 3. Run the executable Editor main.c Compiler hello >>./hello
Cloning a Repository (Repo) git is a way of sharing files; like DropBox or GoogleDrive, only much more powerful (and great for sharing code) more details about this next class We want everyone to have access to class resources for this section our class repo is hosted by bitbucket.org can view the shared files in a browser, but we want local copies to work with today you ll clone the class repo into your ugrad account when instructors add more to the repo, you can pull down updates unlike Dropbox, git doesn t auto-sync the files in the repo
Cloning a Repository (Repo) https://bitbucket.org/minermore/cs120sp17-public.git contains files shared with you for use in this course open a web browser and view this repo
Cloning a Repository (Repo) Cloning to your course folder on your ugrad account: 1. Get into your home directory: >> cd ~ 2. Create a course folder: >> mkdir cs120 3. Change to that directory: >> cd cs120 4. Clone the repo to the course folder: >> git clone https://bitbucket.org/minermore/cs120sp17-public.git
In-Class Exercises On Piazza, find Resources section, then click Resources tab Scroll down to section for this course section Find link for Exercise 1-1 and follow it Follow the instructions; raise your hand if you get stuck Make sure you check in with a course staff member sometime during this session
In-Class Exercises On Piazza, find Resources section, then click Resources tab Scroll down to section for this course section Find link for Exercise 1-1 and follow it Follow the instructions; raise your hand if you get stuck Make sure you check in with a course staff member sometime during this session
In-Class Exercises On Piazza, find Resources section, then click Resources tab Scroll down to section for this course section Find link for Exercise 1-1 and follow it Follow the instructions; raise your hand if you get stuck Make sure you check in with a course staff member sometime during this session
In-Class Exercises On Piazza, find Resources section, then click Resources tab Scroll down to section for this course section Find link for Exercise 1-1 and follow it Follow the instructions; raise your hand if you get stuck Make sure you check in with a course staff member sometime during this session
In-Class Exercises On Piazza, find Resources section, then click Resources tab Scroll down to section for this course section Find link for Exercise 1-1 and follow it Follow the instructions; raise your hand if you get stuck Make sure you check in with a course staff member sometime during this session