Introduction to Unix Editing with emacs Compiling with gcc What is - - PowerPoint PPT Presentation

introduction to unix
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Introduction to Unix

Editing with emacs Compiling with gcc

slide-2
SLIDE 2

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
slide-3
SLIDE 3

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

slide-4
SLIDE 4

Tree Directory Structure

home directory root directory current directory

slide-5
SLIDE 5

Concepts

q Root directory q Current directory q Home directory q Parent directory q Absolute path q Relative path

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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
slide-11
SLIDE 11

A Sample UNIX Directory Listing

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

home directory root directory

Tree Directory Structure

current directory

Unix command: pwd Unix command: mkdir ./bkup/zzz Output: /work

zzz

slide-15
SLIDE 15

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

slide-16
SLIDE 16

home directory root directory current directory

a

Unix command: cp ~/data/a .

zzz

slide-17
SLIDE 17

home directory root directory current directory zzz

a

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

slide-18
SLIDE 18

home directory root directory current directory zzz

a

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

slide-19
SLIDE 19

home directory root directory current directory zzz

a

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

slide-20
SLIDE 20

home directory root directory current directory zzz

a

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

slide-21
SLIDE 21

home directory root directory current directory

a

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

zzz www

slide-22
SLIDE 22

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

slide-23
SLIDE 23

Text editor EMACS

slide-24
SLIDE 24

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

slide-25
SLIDE 25

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

slide-26
SLIDE 26

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

slide-27
SLIDE 27

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

slide-28
SLIDE 28

GCC Compiler

slide-29
SLIDE 29

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

q If you want to learn more, use the manual man gcc

slide-30
SLIDE 30

Helpful Hints

q HOME = ~ = /csc/f19/USERNAME q #include <stdio.h> q Use arrows, not mouse q Mac: Use Ctrl not Cmd q Windows: Edit -> Settings -> Keyboard ->

[X] Backspace sends Delete