CS102B - Lesson 1
Unix, Hello World, Github
Instructor: Professor Hong
Intros
- Name, Major, Year
- What do you hope to get out of this class?
- How many of you have coded before? What languages?
A Bit About Computers
A computer consists of hardware that executes the software.
- System Software - provides a user interface and tools that allow the user to access and use different components of the computer
- Application Software - helps users solve problems and accomplish tasks
Programming Languages
- High Level - more powerful instructions, portable, simpler to understand and use - C, C++
- Low Level - machine languages and assembly languages
Programming Languages
- Interpreted - the computer will run the code by reading through the lines of your code
- Compiled - the computer will run a program that was optimized
Machine Code
- This is what the computer "understands"
- A computer "understands" a stream 1's and 0's.
- bit - a single 0 or 1 in binary
- byte - a sequence of 8 bits; can be represented as a number from 0 to 255
- A compiler converts C code into machine readable instructions
Getting Started
There are several environments that one can use to develop:
- unix machine
- OS terminal - for Apple computers
- Cygwin - for Windows
- When installing, install everything that has gcc, g++, git, and its dependencies.
- You can install everything if you want, but it will take a while and a lot of disk space.
- Other IDEs (Integrated Development Environments)
For the purpose of this class, I will be using Cygwin.
Commands
man - shows you the man(ual) page of the command
Directories
cd directory -- change directory
cd .. -- go back a directory
mkdir directory -- make directory
pwd -- tells you where you currently are
File Access
ls - list directories
ls -l -- lists your files in a long format
ls -a -- lists all files including those that begin with a dot
ls -latrh -- lists all files in long format, in reverse order of the modification time, in human-readable form (use man to read more
File Access (cont.)
mv filename1 filename2 -- moves a file; also renames a file
cp filename1 filename2 -- copies a file
rm filename -- removes a file
rm -rf * -- removes everything!! Make sure you back things up; we will do that later with Github
- Note:
* is a wildcard
File Access (cont.)
diff filename1 filename2 -- diffs 2 files
wc filename -- tells you how many lines, words, and characters are in a file
chmod options filename -- changes the read, write, and executable access for a file
- If you're lazy, you can always do
chmod 777 filename to enable all access for all types of users
touch filename -- creates a blank file or updates the timestamp of the file touched
Finding Stuff
ff -- find files anywhere on the system
grep string filename -- looks for a string in the files in the directory
- Note: there are many useful flags that you can use to make this stronger; see
man grep
Editors
There are various editors that you can use:
- vim
- emacs
- notepad++
- other IDEs (eclipse, etc.)
Note: Depending on the company you end up working for, you may not be able to install certain editors/IDE. You should learn one of the basics - vim or emacs.
vim Quick Guide
vim filename -- to start editing a file with vim
ESC :w -- write/save the file
ESC i -- insert before the character
ESC a -- insert after the character
ESC :q -- quit vim
Writing a Bash Shell Script
#!/bin/bash
mkdir new_folder
cd new_folder
touch new_file.txt
ls
Parts of a C Program
- Consists of variables and functions
- Function - a sequence of statements
- Some functions are part of the C language itself and some are part of the libraries of ANSI C
- You have to tell the compiler which functions you plan on using
- Results in an executable file