36
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques

Lecture 1: Introduction, Basic UNIX

  • Upload
    quant

  • View
    22

  • Download
    3

Embed Size (px)

DESCRIPTION

Lecture 1: Introduction, Basic UNIX. Advanced Programming Techniques. Why are we here?. What’s a computer Why do we run programs? What is needed to create a program?. Applications. Shell \. Kernel (OS). Hardware. Structure of a typical OS. There are many standard applications: - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 1: Introduction,      Basic UNIX

Lecture 1: Introduction, Basic UNIX

Advanced Programming Techniques

Page 2: Lecture 1: Introduction,      Basic UNIX

Why are we here?

What’s a computerWhy do we run programs?What is needed to create a program?

Page 3: Lecture 1: Introduction,      Basic UNIX

Structure of a typical OS

Applications

Shell

\Kernel (OS)

Hardware

There are many standard applications:

• file system commands

• text editors

• compilers

• text processing

Page 4: Lecture 1: Introduction,      Basic UNIX

Logging In

Create Acct www.cs.drexel.edu/Account.php

ClusterPuTTY/SSHLog inPassword

Page 5: Lecture 1: Introduction,      Basic UNIX

Home Directory

The user’s personal directory. E.g., /home/kschmidt /home/vzaychik

Location of many startup and customization files. E.g.:.vimrc .bashrc .bash_profile .forward .si

gnature .plan .logout

Page 6: Lecture 1: Introduction,      Basic UNIX

Unix Filesystem

FilesDirectoriesOther special files

Page 7: Lecture 1: Introduction,      Basic UNIX

The Filesystem (eg)

/

bin etc home/ tmp usr

hollid2 scully bin etc

netprog unix X ls who

Page 8: Lecture 1: Introduction,      Basic UNIX

Pathnames

Unique, on a given filesystemAbsolute vs. relative./ ../ ~/

Page 9: Lecture 1: Introduction,      Basic UNIX

Pathname Examples

/

bin/ etc/ home/ tmp/ usr/

Hollid2/ scully/ bin/ local/

netprog unix/ X ls who

/usr/bin/lsSyllabus

/home/hollid2/unix/Syllabus

Page 10: Lecture 1: Introduction,      Basic UNIX

Commands for Traversing Filesystem

lspwdcdrmcpmvmkdirrmdir

Page 11: Lecture 1: Introduction,      Basic UNIX

Viewing files

cat

less, more od

Comparing files diff cmp

Page 12: Lecture 1: Introduction,      Basic UNIX

Copying, removing, linking

rm – remove filemv – move (rename) filecp – copy fileln – create hard (inode) or soft (symbolic) links to a filetouch – update file modification time, create an empty file if file doesn’t exist

Page 13: Lecture 1: Introduction,      Basic UNIX

Commands for directories

mkdir make directoryrmdir remove directoryDirectories can also be moved or renamed (mv), and copied (cp –r)

Page 14: Lecture 1: Introduction,      Basic UNIX

Commands for Archiving

tar – Tape Archive makes a large file from many files

gzip, gunzip compression utility

tar on Linux does compression with the z option:$ tar czf 571back.tgz CS571

$ tar xzf assn1.tgz

Page 15: Lecture 1: Introduction,      Basic UNIX

File Permissions

Three types: read abbreviated r write abbreviated w execute abbreviated x

There are 3 sets of permission:1. user2. group3. other (the world, everybody else)

Page 16: Lecture 1: Introduction,      Basic UNIX

ls -l and permissions

-rwxrwxrwx User Group Others

Type of file:- – plain filed – directorys – symbolic link

Page 17: Lecture 1: Introduction,      Basic UNIX

Bourne-again Shell (bash)

ShellsStartup Upon login (interactive), at the shell

prompt customization files:

/etc/profile .bash_profile .bashrc

Page 18: Lecture 1: Introduction,      Basic UNIX

Command syntax

First token is the “command”Come in 3 flavors: alias shell builtin External programs (utilities)

$PATH

Use type

Page 19: Lecture 1: Introduction,      Basic UNIX

Command Options and Arguments

command option(s) arguments

Options (flags) Short Long Option args

Arguments

Page 20: Lecture 1: Introduction,      Basic UNIX

man Pages

maninfo

Page 21: Lecture 1: Introduction,      Basic UNIX

Some simple commandsdate – print current datewho – print who is currently logged infinger usr – more information about usrls -ao – lists (long) all files in a directorydu -sh – disk usage summary, human readablequota

Page 22: Lecture 1: Introduction,      Basic UNIX

Standard I/OThe shell establishes 3 I/O channels: stdin (0) stdout (1) stderr (2)

These streams my be redirected to/from a file, or even another command

Page 23: Lecture 1: Introduction,      Basic UNIX

Basic control codes

Ctrl-D (^D) set ignoreeof

Ctrl-C (^C)Ctrl-U (^U)Ctrl-Z (^Z)Ctrl-L (^L)

Page 24: Lecture 1: Introduction,      Basic UNIX

Shell metacharactersSome characters have special meaning to the shell: I/O redirection< > |

wildcards* ? [ ]

others& ; $ ! \ ( ) space tab newline

These must be escaped or quoted to inhibit special behavior

Page 25: Lecture 1: Introduction,      Basic UNIX

Shell Variables

ValuesAssignmentReading

Page 26: Lecture 1: Introduction,      Basic UNIX

Shell maintains variables

Some common ones:$PATH – list of directories to search for

utilities$PS1 – Primary prompt$HOME – user’s home directory$USER – user’s login name$PWD – current working directory

Page 27: Lecture 1: Introduction,      Basic UNIX

set command (shell builtin)

The set command with no parameters will print out a list of all the shell variablesSets options in the shell -o -noclobber -ignoreeof

Page 28: Lecture 1: Introduction,      Basic UNIX

Quoting

Escape charStrong quotingWeak quoting

Page 29: Lecture 1: Introduction,      Basic UNIX

I/O Redirection

> - output to a file (clobber)>> - append< - input from a file2> - redirect stderr

Page 30: Lecture 1: Introduction,      Basic UNIX

Pipes – connecting processes

A pipe is a holder for a stream of data.A pipe can be used to hold the output of one program and feed it to the input of another.

prog1prog1 prog2prog2STDOUT STDIN

Page 31: Lecture 1: Introduction,      Basic UNIX

filtersPrograms that read some input (but don’t change it), perform a simple transformation on it, and write some output (to stdout)Some common filters… wc – word count (line count, character count) tr – translate grep, egrep – search files using regular

expressions sort – sorts files by line (lexically or

numerically) cut – select portions of a line uniq – Removes identical adjacent lines head, tail – displays first (last) n lines of a file

Page 32: Lecture 1: Introduction,      Basic UNIX

The Unix Philosophy

Stringing small utilities together with pipes and redirection to accomplish non-trivial tasks easilyE.g., find the 3 largest subdirectories:$ du –sh * | sort –nr | head -3120180 Files

22652 Zaychik

9472 tweedledee.tgz

Page 33: Lecture 1: Introduction,      Basic UNIX

pipes and combining filters

Connect the output of one command to the input of another command to obtain a composition of filters

who | wc -lls | sort -fls -s | sort -nls -l | sort -nr -k4ls -l | grep ‘^d’

Page 34: Lecture 1: Introduction,      Basic UNIX

Process ControlProcesses run in a subshellSubshells inherit exported variablesEach process is has an ID (pid) and a parent (ppid)Use the ps utility to look at some processes:$ ps

PID TTY TIME CMD 350 pts/4 00:00:00 bash22251 pts/4 00:00:00 vim22300 pts/4 00:00:00 ps

Page 35: Lecture 1: Introduction,      Basic UNIX

Job Control

The shell allows you to manage jobs place jobs in the background move a job to the foreground suspend a job kill a job

Page 36: Lecture 1: Introduction,      Basic UNIX

EditorsA text editor is used to create and modify text files.The most commonly used editors in the Unix community: vi (vim on Linux)

$ vimtutor emac

$ emacs Then, hit ctrl-h t (that’s control-h, followed by ‘t’)

You must learn at least one of these editors