CSE2031 Software Tools - UNIX introduction Przemyslaw CSE2031 Software Tools - UNIX introduction Pawluk presented by Shakil Khan Summer 2010 Introduction to UNIX UNIX Shells Commands Overview Przemyslaw Pawluk grep family presented by Shakil Khan The AWK Programming Language Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 41
Table of contents CSE2031 Software Tools - UNIX introduction Przemyslaw Introduction to UNIX 1 Pawluk presented by Shakil Khan Introduction UNIX Shells 2 to UNIX UNIX Shells Commands Overview Commands Overview 3 grep family The AWK Programming Language grep family 4 The AWK Programming Language 5 2 / 41
Plan CSE2031 Software Tools - UNIX introduction Przemyslaw Introduction to UNIX 1 Pawluk presented by Shakil Khan Introduction UNIX Shells 2 to UNIX UNIX Shells Commands Overview Commands Overview 3 grep family The AWK Programming Language grep family 4 The AWK Programming Language 5 3 / 41
Our goal CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction to UNIX UNIX Shells Our goal is to see how we can use Unix as a tool for developing Commands programs Overview grep family The AWK Programming Language 4 / 41
Processes CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction Each running program on a Unix system is called a process to UNIX UNIX Shells Processes are identified by a number (process id or PID) Commands Overview Usually many processes running simultaneously grep family Each process has a unique PID The AWK Programming Language 5 / 41
Current Working Directory CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction Every process has a current working directory to UNIX In a shell, the command ls shows the contents of the current UNIX Shells Commands working directory Overview pwd shows the current working directory grep family The AWK cd changes the current working directory Programming Language 6 / 41
Path names CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan A path name is a reference to something in the filesystem Introduction A path name specifies the set of directories you have to pass to UNIX through to find a file UNIX Shells Commands Directory names are separated by ’/’ in Unix Overview grep family Path names beginning with ’/’ are absolute path names. The AWK Programming Path names that do not begin with ’/’ are relative path names Language (Start search in current working directory) 7 / 41
Special characters CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk . means ”the current directory” presented by Shakil Khan .. means ”the parent directory” Introduction to UNIX ~ means ”home directory” UNIX Shells Commands Overview Try grep family The AWK l s . 1 Programming Language l s . . 2 l s ˜ 3 8 / 41
Devices in UNIX CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by /dev contains devices Shakil Khan Look like files but really communicate with devices. Introduction to UNIX For example: UNIX Shells Commands /dev/tty the terminal (or virtual terminal) you are currently using Overview grep family /dev/zero an input stream which returns an endless stream of The AWK null bytes ( ’\0’ ) Programming Language /dev/null the bitbucket discards any input, generates no output (empty) 9 / 41
Use of dev/null CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction To discard stdout of a command: to UNIX cat hello.c >/dev/null UNIX Shells Commands Overview To provide no input to a command: grep family The AWK cat </dev/null Programming Language 10 / 41
Plan CSE2031 Software Tools - UNIX introduction Przemyslaw Introduction to UNIX 1 Pawluk presented by Shakil Khan Introduction UNIX Shells 2 to UNIX UNIX Shells Commands Overview Commands Overview 3 grep family The AWK Programming Language grep family 4 The AWK Programming Language 5 11 / 41
Shells – intro CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan What is shell? Introduction Ordinary program which acts as a command interpreter and offers to UNIX multiple benefits including UNIX Shells Commands Filename shorthand Overview grep family I/O redirection The AWK Personalizing the environment Programming Language Programming language 12 / 41
Shells CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan There are many programs which are shells Introduction to UNIX The most common Unix shells are: UNIX Shells Bourne shell (sh) Commands C shell (csh) Overview Korn shell (ksh) grep family Also: Bourneagain shell (bash). The AWK Programming Language In this course we are mostly concerned with the Bourne shell (sh) 13 / 41
How does it work? CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction When a command is entered shell does to UNIX UNIX Shells Process metacharacters Commands Overview Command line substitution grep family Command execution The AWK Programming Language 14 / 41
Special Characters CSE2031 Software Tools - UNIX introduction Przemyslaw > >> < | – IO redirection Pawluk presented by * ? [...] – Filename shorthand Shakil Khan ’command’ – Command substitution Introduction to UNIX || && – Conditional execution UNIX Shells Commands (...) – Group commands Overview & – Background processing grep family The AWK <<tok – Here document Programming Language $ – Expand value \ # ; – Escape, comment, terminator ’ " – Single/double quotes 15 / 41
Plan CSE2031 Software Tools - UNIX introduction Przemyslaw Introduction to UNIX 1 Pawluk presented by Shakil Khan Introduction UNIX Shells 2 to UNIX UNIX Shells Commands Overview Commands Overview 3 grep family The AWK Programming Language grep family 4 The AWK Programming Language 5 16 / 41
Commands Overview CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction to UNIX Basic tools: ls, cp, mv, ... UNIX Shells Commands Advanced tools: Overview grep, sort, cut, uniq, tr, find, xargs, sed, awk grep family The AWK Programming Language 17 / 41
Basic Unix Commands(1) CSE2031 Software Tools - UNIX introduction ls list directory content Przemyslaw Pawluk cp file copy presented by Shakil Khan mv file renaming, moving Introduction rm delete files to UNIX UNIX Shells mkdir create a new directory Commands Overview cd change directory grep family pwd print current working directory The AWK Programming cat print text files Language more print text files page by page less view text files head print first part of a text file tail print last part of a text file 18 / 41
Basic Unix Commands(2) CSE2031 Software Tools - UNIX expr evaluate an expression introduction Przemyslaw echo display a line of text Pawluk presented by date print and set system date and time Shakil Khan ps process status Introduction to UNIX kill kill a process (send a signal) UNIX Shells Commands top display top CPU processes Overview grep family od octal dump of a file The AWK du disk usage Programming Language chmod change file access permission chgrp change group ownership ln link files diff difference of two files basename base name of a full path name 19 / 41
Combining Commands CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk If we just run a command, e.g. wc then the terminal is used for stdin , presented by Shakil Khan stdout , and stderr by default. However, we dont need to use the terminal. We can control what stdin , stdout , and stderr refer to. Introduction to UNIX UNIX Shells The simple case is redirection using a file Commands Overview wc <foo/bar/file grep family i.e. use the contents of the file "foo/bar/file" instead of the The AWK terminal for stdin Programming Language wc >foo/bar/file i.e. put the output of stdout into "foo/bar/file" instead of the terminal 20 / 41
Pipes CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction to UNIX We can also redirect stdout or stdin to other programs (instead of files) UNIX Shells cat myfile | wc Commands Overview this takes the stdout of the cat myfile command and makes it the stdin grep family of the wc command The AWK Programming Language 21 / 41
Shell Scripting CSE2031 Software Tools - UNIX introduction Przemyslaw Pawluk presented by Shakil Khan Introduction to UNIX A shell provides UNIX Shells Basic interactive shell Commands Overview Programming environment grep family The AWK Programming Language 22 / 41
Recommend
More recommend