<<

Introduction to

Editing with emacs Compiling with gcc What is Unix? q UNIX is an first developed in the 1960s - by operating system, we mean the suite of programs that the computer work q There are many different versions of UNIX, although they share common similarities - the most popular varieties of UNIX are Sun Solaris, GNU/, and MacOS X q The UNIX operating system is made up of three parts: - the kernel, the shell and the programs Files and Processes q Everything in UNIX is either a or a process: - A process is an executing program identified by a unique process identifier - a file is a collection of data created by users using text editors, running compilers, etc. q All the files are grouped together in the structure - The file-system is arranged in a hierarchical structure, like an inverted tree Tree Directory Structure

root directory

home directory current directory Concepts q Root directory q Current directory q Home directory q Parent directory q Absolute q Relative path Tree Directory Structure

Unix : root directory Output: Sub a b c

Unix command: home ls /home/jane/data directory current Output: directory Sub a b c

Unix command: ls ~/data Output: Sub a b c Tree Directory Structure

Unix command: root ls ~ directory Output: data setup

Unix command: home ls .. directory Output: current directory data setup

Unix command: ls ./../.. Output: jim jane

Unix command: ls ./../../jim Output: calendar Tree Directory Structure

Unix commands: root ./../../../work directory current ls directory Output: setups bkup

home Unix command: directory ls ./.. Output: home work

Unix command: ls / Output: home work

Unix command: ls /home Output: jim jane Tree Directory Structure

Unix commands: root ls ~/.. directory current Output: directory jim jane

Unix command: home ls ~/../.. directory Output: home work

Unix command: ls setups Output: generic Unix file security q Each file has owner and group q Permissions set by owner - Read, , execute - Owner, group, other q Only owner, root can change permissions - This privilege cannot be delegated or shared A Sample UNIX Directory Listing Changing Access Rights q Use the command

For example, to remove read write and execute permissions on the file biglist for the group and others,

chmod go-rwx biglist

This will leave the owner’s permissions unaffected.

To give read and write permissions on the file biglist to all,

chmod o+rw biglist Basic Unix Commands (1) ls list files and directories ls -a list all files and directories cd name change to named directory cd change to home directory cd ~ change to home directory cd .. change to parent directory name make a directory display current directory path Tree Directory Structure

Unix command: root directory mkdir ./bkup/zzz current directory

Unix command: pwd Output: home /work directory

zzz Basic Unix Commands (2) file1 file2 make a of file1 into file2 cp -r dir1 dir2 make a copy of directory dir1 into dir2 file1 file2 or rename file1 to file2 file remove a file rm –r directory remove a directory file display a file less file display a file a page a list users currently logged in * match any number of characters ? match one character man read online manual for a command Unix command: cp ~/data/a .

root directory current directory

home a directory

zzz Unix command: cp –r /home/jim/calendar ./bkup/zzz

root directory current directory

home a directory

zzz Unix command: cp –r /home/jim/calendar/* ./bkup/zzz

root directory current directory

home a directory

zzz Unix command: rm –r /home/jim/calendar/*

root directory current directory

home a directory

zzz Unix command: rm –r /home/jim/calendar/*

root directory current directory

home a directory

zzz Unix command: mv ./bkup/zzz ./bkup/www

root directory current directory

home a directory

zzz www Basic Unix Commands (3)

command > file redirect standard output to a file command >> file append standard output to a file command < file redirect standard input from a file keyword file search a file for keywords file count number of words in file sort data (numerically or alphabetically Text editor EMACS Text Editor emacs q Configurable, extensible text editor q To emacs just “call it” emacs q Basic editing in emacs is somewhat intuitive - use arrows, “PG UP”and “PG DOWN”to move cursor - use key to delete - typing inserts text at the cursor position q To edit an existing file type emacs filename Using emacs: keyboard commands q We use the following abreviations “C” is the “Control” key “-” between two letters mean both have to be pressed simultaneously q Basic commands C-x, C-s to save the file C-x, C-c to Emacs C-g to get out of trouble Basic emacs Commands q Cursor movement q Copy - C-a (begin of line) C-c - C-e (end of line) q C-v - C-v (page up) q Undo - alt-v (page down) C-x u q Delete q Save/Quit C-k (delete line) - C-x C-c (quit w/out saving) q Cancel - C-x C-s (save) - C-x C-w (write to a new file) C-g q Load file - C-x C-f (delete line) Searching in Emacs q C-s : search for a string – this search is incremental and goes as you search – typing C-s again will search for the next occurrence of the same string – to go back to the editing, just press any arrow key – after you go back, typing C-s twice resumes the search GCC Compiler What is gcc? q Stands for GNU C/C++ Compiler q Popular console-based compiler for Unix platforms q Compile and link C programs: gcc filename.c output is an executable called a.out q Another option (we will be using this one): gcc filename.c –o xfilename

output is an executable called xfilename q If you want to learn , use the manual man gcc