Introduction to Unix Editing with emacs Compiling with gcc What is - - PowerPoint PPT Presentation
Introduction to Unix Editing with emacs Compiling with gcc What is - - PowerPoint PPT Presentation
Introduction to Unix Editing with emacs Compiling with gcc What is Unix? q UNIX is an operating system first developed in the 1960s - by operating system, we mean the suite of programs that make the computer work q There are many different
What is Unix?
q UNIX is an operating system first developed in the 1960s
- by operating system, we mean the suite of programs that make 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/Linux, 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 file 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 directory structure
- The file-system is arranged in a hierarchical structure, like an
inverted tree
Tree Directory Structure
home directory root directory current directory
Concepts
q Root directory q Current directory q Home directory q Parent directory q Absolute path q Relative path
home directory root directory
Tree Directory Structure
current directory
Unix command: ls /home/jane/data Unix command: ls Output: Sub a b c Output: Sub a b c Unix command: ls ~/data Output: Sub a b c
home directory root directory
Tree Directory Structure
current directory
Unix command: ls .. Unix command: ls ~ Output: data setup Output: data setup Unix command: ls ./../.. Output: jim jane Unix command: ls ./../../jim Output: calendar
home directory root directory
Tree Directory Structure
current directory
Unix command: ls ./.. Unix commands: cd ./../../../work ls Output: setups bkup Output: home work Unix command: ls / Output: home work Unix command: ls /home Output: jim jane
home directory root directory
Tree Directory Structure
current directory
Unix command: ls ~/../.. Unix commands: ls ~/.. Output: jim jane Output: home work Unix command: ls setups Output: generic
Unix file security
q Each file has user and group q Permissions set by user
- Read, write, execute
- User, group, other
q Only user, root can change permissions
- This privilege cannot be delegated or shared
A Sample UNIX Directory Listing
Changing Access Rights
q
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-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 mkdir name make a directory pwd display current directory path
home directory root directory
Tree Directory Structure
current directory
Unix command: pwd Unix command: mkdir ./bkup/zzz 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 mv file1 file2 move or rename file1 to file2 rm file remove a file rm –r directory remove a directory cat file 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
home directory root directory current directory
a
Unix command: cp ~/data/a .
zzz
home directory root directory current directory zzz
a
Unix command: cp –r /home/jim/calendar ./bkup/zzz
home directory root directory current directory zzz
a
Unix command: cp –r /home/jim/calendar/* ./bkup/zzz
home directory root directory current directory zzz
a
Unix command: rm –r /home/jim/calendar/*
home directory root directory current directory zzz
a
Unix command: rm –r /home/jim/calendar/*
home directory root directory current directory
a
Unix command: mv ./bkup/zzz ./bkup/www
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 grep keyword file search a file for keywords wc file count number of words in file sort sort data (numerically or alphabetically
Text editor EMACS
Text Editor emacs
q Configurable, extensible text editor q To start emacs just “call it”
emacs
q 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
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 exit Emacs C-g to get out of trouble
Basic emacs Commands
q Cursor movement
- C-a (begin of line)
- C-e (end of line)
- C-v (page up)
- alt-v (page down)
q
Save/Quit
- C-x C-c (quit w/out saving)
- C-x C-s (save)
- C-x C-w (write to a new file)
q Load file
- C-x C-f (delete line)
q
Copy
C-c
q
Paste
C-v
q
Undo
C-x u
q
Delete
C-k (delete line)
q
Cancel
C-g
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
- utput is an executable called a.out
q Another option (we will be using this one): gcc filename.c –o xfilename
- utput is an executable called xfilename