290 likes | 298 Vues
Introduction to Unix Editing with emacs Compiling with gcc. What is Unix?. UNIX is an operating system first developed in the 1960s by operating system, we mean the suite of programs that make the computer work
E N D
Introduction to Unix Editing with emacs Compiling with gcc
What is Unix? • UNIX is an operating system first developed in the 1960s • by operating system, we mean the suite of programs that make the computer work • There are many different versions of UNIX, although they share common similarities • the most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X • The UNIX operating system is made up of three parts: • the kernel, the shell and the programs
Files and Processes • Everything in UNIX is either a file or a process: • A process is an executing program identified by a unique process identifier • afile is a collection of data created by users using text editors, running compilers, etc. • All the files are grouped together in the directory structure • The file-system is arranged in a hierarchical structure, like an inverted tree
Tree Directory Structure root directory home directory current directory
Concepts • Root directory • Current directory • Home directory • Parent directory • Absolute path • Relative path
Tree Directory Structure Unix command: ls root directory Output: Sub a b c Unix command: ls /home/jane/data home directory current directory Output: Sub a b c Unix command: ls ~/data Output: Sub a b c
Tree Directory Structure Unix command: ls ~ root directory Output: data setup Unix command: ls .. home directory current directory Output: data setup Unix command: ls ./../.. Output: jim jane Unix command: ls ./../../jim Output: calendar
Tree Directory Structure Unix commands: cd ./../../../work ls root directory current directory Output: setups bkup home directory Unix command: ls ./.. Output: home work Unix command: ls / Output: home work Unix command: ls /home Output: jim jane
Tree Directory Structure Unix commands: ls ~/.. root directory current directory Output: jim jane Unix command: ls ~/../.. home directory Output: home work Unix command: ls setups Output: generic
Unix file security • Each file has owner and group • Permissions set by owner • Read, write, execute • Owner, group, other • Only owner, root can change permissions • This privilege cannot be delegated or shared
Changing Access Rights • Use the command chmod For example, to remove read write and execute permissions on the file biglist for the group and others, type chmod go-rwxbiglist This will leave the owner’s permissions unaffected. To give read and write permissions on the file biglist to all, chmodo+rwbiglist
Basic Unix Commands (1) ls list files and directories ls -a list all files and directories cdname change to named directory cdchange to home directory cd ~ change to home directory cd .. change to parent directory mkdirnamemake a directory pwd display current directory path
Tree Directory Structure root directory Unix command: mkdir./bkup/zzz current directory Unix command: pwd home directory Output: /work zzz
Basic Unix Commands (2) cp file1 file2 make a copy of file1 into file2 cp -r dir1 dir2 make a copy of directory dir1 into dir2 mvfile1 file2 move or rename file1 to file2 rm file remove a file rm –r directory remove a directory catfile display a file less file display a file a page at a time who 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 directory zzz a
Unix command: cp–r /home/jim/calendar ./bkup/zzz root directory current directory home directory zzz a
Unix command: cp–r /home/jim/calendar/* ./bkup/zzz root directory current directory home directory zzz a
Unix command: rm–r /home/jim/calendar/* root directory current directory home directory zzz a
Unix command: rm–r /home/jim/calendar/* root directory current directory home directory zzz a
Unix command: mv ./bkup/zzz ./bkup/www root directory current directory home directory zzz www a
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 grep keywordfile search a file for keywords wcfile count number of words in file sort sort data (numerically or alphabetically
Text Editor emacs • Configurable, extensible text editor • To start emacs just “call it” emacs • Basic editing in emacs is somewhat intuitive • use arrows, “PG UP”and “PG DOWN”to move cursor • use DEL key to delete • typing inserts text at the cursor position • To edit an existing file type emacsfilename
Using emacs: keyboard commands • We use the following abreviations “C” is the “Control” key “-” between two letters mean both have to be pressed simultaneously • Basic commands C-x, C-s to save the file C-x, C-c to exit Emacs C-g to get out of trouble
Basic emacs Commands Cursor movement C-a (begin of line) C-e (end of line) C-v (page up) alt-v (page down) Save/Quit C-x C-c (quit w/out saving) C-x C-s (save) C-x C-w (write to a new file) Load file C-x C-f (delete line) Copy C-c Paste C-v Undo C-x u Delete C-k (delete line) Cancel C-g
Searching in Emacs • 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
What is gcc? • Stands for GNU C/C++ Compiler • Popular console-based compiler for Unix platforms • Compile and link C programs: gccfilename.c output is an executable called a.out • Another option (we will be using this one): gccfilename.c–oxfilename output is an executable called xfilename • If you want to learn more, use the manual man gcc