11
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6. Compiling and Running C Programs in UNIX

Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Embed Size (px)

Citation preview

Page 1: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Introduction to UNIXRoad Map:1. UNIX Structure2. Components of UNIX3. Process Structure4. Shell & Utility Programs5. Using Files & Directories6. Compiling and Running C Programs in UNIX

Page 2: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

UNIX Structure

Multiuser : Several users can use a UNIX system at the same time.

Multitasking : Can run multiple processes at the same time.

Hardware

UNIX KernelPOSIX system call API

P1 P2 PN…

Page 3: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Components of UNIX

1. Kernel + POSIX system call API◦ Covered in OS

2. Shell (program to launch other programs)

3. Standard utility programs ◦(cp, mv, ls, cat, …)

4. System configuration files◦(/etc/vfstab,…)

Page 4: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Process Structure

init

login login (/bin/login)

login

shell (/bin/sh)

ls wc cat

Other user programs

Page 5: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Logging In/Out

Login : user1Password: 123

% command get a shell prompt% command get another shell prompt% exit logout & terminate shell

Page 6: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Shell

a.k.a command line interpreter

Getting help on UNIX% man ls% man man

while(1)1. prompt the user for the next command2. Read the next command3. Parse the command line4. Launch the programs (fork, exec)5. Wait until the programs terminate

(waitpid)end

Page 7: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Running utility programsMost utility programs are located

in /usr/binBasic form of a UNIX command is

% command [-options] [arguments]

Ex:

% ls

% ls –a

% ls –al

% ls BIM322

% ls –al BIM322

% clear cleans the screen

Aborting a shell command: press ^C

Page 8: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

UNIX has a tree-like hierarchical directory structure.

When you login, login utility reads your home directory from /etc/passwd and changes your current directory to be your home directory.

Using Files & Directories

tmp bin lib usr etc home export dev

include bin local

bin

Page 9: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Directories1. % pwd print working directory2. % cd BIM322 change current directory % cd .. change to parent % cd / change to root % cd /usr/local absolute path specification % cd % cd ~ takes you to your home % cd ~cakinlar directory3. % ls –al list directory content4. % mkdir AA create a new directory5. % rmdir AA remove a directory

Page 10: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Files1. % touch file1 create an empty file2. % cp file1 file2 copy files3. % mv file1 /tmp move file to directory % mv file1 file3 move file to a new file % mv AA /tmp can also move directories4. % rm file1 remove a file5. % find . –name file1 find a file6. % cat file1 view all at once7. % more file1 page by page8. % head file1 first … lines9. % tail file1 last … lines

Page 11: Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6

Compiling and Running C Programs in UNIX1. Open an editor, type your ‘Hello world’

program.

2. % gcc first.c outputs a.out3. % ./a.out or % ./a4. % gcc –o first first.c5. % ./first

// first.cinclude <stdio.h>int main(int argc, char *argv[]){ int i; for(i=0; i<argc; i++) printf("arg[%d]: %s\n", i, argv[i]);} //end-main