INTRODUCTION TO UNIX: The Shell Command Interface

Slides:



Advertisements
Similar presentations
UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
Advertisements

CHAPTER 2 THE UNIX SHELLS by U ğ ur Halıcı. layers in a unix system 1 Users Standard utility programs (shell, editors, compilers, etc.) Standard utility.
A Guide to Unix Using Linux Fourth Edition
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
The Unix Shell. Operating System shell The shell is a command interpreter It forms the interface between a user and the operating system When you log.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Advanced File Processing
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Lesson 11-Locating, Printing, and Archiving User Files.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Jozef Goetz, expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
Introduction to Programming Using C An Introduction to Operating Systems.
CSC414 “Introduction to UNIX/ Linux” Lecture 5. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Learning Unix/Linux Based on slides from: Eric Bishop.
Introduction to Scripting Workshop February 23, 2016.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Chapter 11 Command-Line Master Class
Prepared by: Eng. Maryam Adel Abdel-Hady
The UNIX Shell Learning Objectives:
Some Linux Commands.
Chapter 6 Filters.
Shell Script Assignment 1.
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Tutorial of Unix Command & shell scriptS 5027
Introduction to Linux Week 0 - Thursday.
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
UNIX Reference Sheets CSE 2031 Fall 2010.
Tutorial Unix Command & Makefile CIS 5027
Linux Shell Script Programming
Linux Commands LINUX COMMANDS.
Presentation transcript:

INTRODUCTION TO UNIX: The Shell Command Interface © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved The UNIX shell The primary UNIX user interface A command interpreter A powerful programming language, includes facilities for execution of processes combination of processes control structures and variables © Ronald J. Leach All Rights Reserved

Example - connecting processes Problem - computing the percentage of misspelled words in a document Most word processors have a spell checkers These word processors don't usually provide counts of spelling errors We don’t want to write a program by hand © Ronald J. Leach All Rights Reserved

Connecting processes, cont. A simple UNIX shell program wc -w filename spell filename | wc - w The first line counts the number of words in "filename” invoking the wc utility (the -w option counts only the number of words) The second line uses the spell utility and sends the results to the wc utility © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved Pipes in the UNIX shell The character '|' is called the pipe symbol Connects two UNIX processes The connection of two processes by a pipe is automatic (in the UNIX shell) and requires no special programming © Ronald J. Leach All Rights Reserved

Modifying shell programs: an example Count the misspelled words in a file Ignore any duplications Hard to modify a program in a standard programming language to do this In UNIX, we just use some additional building blocks © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved The new shell program cat filename | unique | wc -w spell filename | wc -w The UNIX utility cat lists all the contents of the file on the terminal screen. A user-written utility, unique, is to produce a list of the unique occurrences of words in the file © Ronald J. Leach All Rights Reserved

The user-written unique utility Made up of three standard UNIX utilities: tr, sort, and uniq Process the input file to one word per line Output only one occurrence of each word Sort the lines into alphabetical order © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved Unique, cont. Each step involves an output that is a transformation of its input The original input is not affected since we use a copy of the file ( produced by cat) tr translates characters specified in its first argument into characters specified in the second argument © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved Unique, cont. Input: The frog and the dog went to study the compter at the dog house Output (combined five per line, to fit on one slide): The frog and the dog went to study the compter at the dog house © Ronald J. Leach All Rights Reserved

Some non-portability issues In the C shell, the tr utility is used like tr -c 'A-Za-z' '\12' while in the Bourne shell that is most common in System V UNIX, the usage would be tr -c '[A-Z][a-z]' '[\12*]’ The \12 is the ASCII new line character © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved Unique, cont. The unique utility is therefore tr -c 'A-Za-z' '\12’ | sort |uniq in the C shell and tr -c '[A-Z][a-z]' '[\12*]’ | sort |uniq in the Bourne shell Create a file name unique with the appropriate contents © Ronald J. Leach All Rights Reserved

How to make unique executable Change the “mode” to make it executable by the shell chmod +x unique Each file has 3 sets of permissions: read, write, execute for each of owner, group, world © Ronald J. Leach All Rights Reserved

An important shell command: find find has many possible variations Like most shell commands, it has multiple uses The manual pages are sometimes confusing man find Can be combined with other utilities © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved find, cont. To list all files in current directory: find . -name * -print The . indicates the current directory The -name option says we search the directory until we match the name, *, which is a wild card The -print option says print what we find. © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved find, cont We can compare a file in NEW_DIR to an existing file to see if they are the same find NEW_DIR -name REUSED_FILE -print | diff REUSED_FILE This technique saved 19% in a reengineering project by determining identical modules in a project with poor editors and naming conventions © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved find, cont Can be combined with other utilities exec can be used to add executable files with arguments find /dir1 /dir2 -exec grep -l ‘Buy Advanced Topics in UNIX’{} \; © Ronald J. Leach All Rights Reserved

© Ronald J. Leach All Rights Reserved Some shell scripts # Code used to analyze FORTRAN files echo "STARTING ANALYSIS “ mkdir $1 cp COPY/* $1 cd $1 # Now the main loop © Ronald J. Leach All Rights Reserved

Some shell scripts, cont. for i in [A-Z]* do echo "Creating Directory $i.DIR..." mkdir $i.DIR mv $i $i.DIR/$i.SEQ done © Ronald J. Leach All Rights Reserved

Some shell scripts, cont. for i in *.DIR do cd $i echo "DATA ANALYSIS FOR <=================> $i">>$i.DOC echo "FILES\t\t\tSTART DATE\tFINISHED DATE\t\tCOMMENTS">>$i.DOC echo "-----------------------------------">>$i.DOC © Ronald J. Leach All Rights Reserved

Some shell scripts, cont. for j in *.SEQ do csplit -s -k -f $j $j '/ADD NAME/+1' '{99}' rm -f $j done for j in *[0-9] mkdir $j.DIR © Ronald J. Leach All Rights Reserved

Some shell scripts, cont. echo $j>>$i.DOC floppy -t -cn $j>>$j.txt flow -g $j.floptre>>$j.txt1 rm -f *.floptre *.flopold mv $j* $j.DIR mv flow.ps $j.DIR done cd ../ SCRIPT TO COMPILE THE FORTRAN SOURCE CODE for i in *.f do f77 -col72 $i SCRIPT TO SEPARATE FORTRAN, ASSEMBLY, AND DOCUMENTATION for i in *.DIR cd $i cp *.f REUSE/IMP8.18/FORTRANFILES/DISK cp *.txt2 REUSE/IMP8.18/DOCUMENTATION cp *.a REUSE/IMP8.18/ASSEMBLY © Ronald J. Leach All Rights Reserved

Shell scripts to compile FORTRAN source code for i in *.f do f77 -col72 $i done © Ronald J. Leach All Rights Reserved

Shell script to separate FORTRAN, assembly, ... for i in *.DIR do cd $i cp *.f REUSE/IMP8.18/FORTRANFILES/DISK cp *.txt2 REUSE/IMP8.18/DOCUMENTATION cp *.a REUSE/IMP8.18/ASSEMBLY cd ../ done © Ronald J. Leach All Rights Reserved