The Unix Shell. Pipes and Filters

Similar documents
The Unix Shell. Permissions

The Shell. EOAS Software Carpentry Workshop. September 20th, 2016

Introduction to Linux

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

CSCI 2132 Software Development. Lecture 4: Files and Directories

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Unix Shell. Advanced Shell Tricks

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

Lab 2: Linux/Unix shell

Introduction To. Barry Grant

Advanced Linux Commands & Shell Scripting

Perl and R Scripting for Biologists

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Files

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Recap From Last Time:

BGGN 213 Working with UNIX Barry Grant

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Introduction to UNIX. Introduction. Processes. ps command. The File System. Directory Structure. UNIX is an operating system (OS).

Introduction to UNIX. CSE 2031 Fall November 5, 2012

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

The Unix Shell. Job Control

Files and Directories

Shell Programming Systems Skills in C and Unix

Computer Systems and Architecture

Introduction: What is Unix?

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Essential Linux Shell Commands

UNIX Essentials Featuring Solaris 10 Op System

A Brief Introduction to Unix

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

Introduction To. Barry Grant

The Unix Shell. Files and Directories

Common File System Commands

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Week 2 Lecture 3. Unix

Useful Unix Commands Cheat Sheet

UNIX Tutorial Two

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen

Part 1: Basic Commands/U3li3es

Chapter 4. Unix Tutorial. Unix Shell

Scripting Languages Course 1. Diana Trandabăț

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Laboratory 1 Semester 1 11/12

Introduction to UNIX command-line II

Mills HPC Tutorial Series. Linux Basics I

Recap From Last Time: Setup Checklist BGGN 213. Todays Menu. Introduction to UNIX.

Linux Shell Script. J. K. Mandal

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

Linux Command Line Primer. By: Scott Marshall

COSC UNIX. Textbook. Grading Scheme

System Administration

The Unix Shell & Shell Scripts

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

CSCI 2132 Software Development. Lecture 5: File Permissions

Introduction To Linux. Rob Thomas - ACRC

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Introduction of Linux

Lec 1 add-on: Linux Intro

18-Sep CSCI 2132 Software Development Lecture 6: Links and Inodes. Faculty of Computer Science, Dalhousie University. Lecture 6 p.

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Introduction to UNIX command-line

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Linux Bootcamp Fall 2015

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

Physics REU Unix Tutorial

Using Linux as a Virtual Machine

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

Automated Builds. Rules

Computer Systems and Architecture

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Running Programs in UNIX 1 / 30

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Cloud Computing and Unix: An Introduction. Dr. Sophie Shaw University of Aberdeen, UK

Where can UNIX be used? Getting to the terminal. Where are you? most important/useful commands & examples. Real Unix computers

Cloud Computing and Unix: An Introduction. Dr. Sophie Shaw University of Aberdeen, UK

Std: XI CHAPTER-3 LINUX

UNIX Basics. UNIX Basics CIS 218 Oakton Community College

Practical 02. Bash & shell scripting

Unix Basics. Systems Programming Concepts

A Brief Introduction to the Linux Shell for Data Science

Unix Tools / Command Line

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Introduction to Linux

LAB 8 (Aug 4/5) Unix Utilities

MBV4410/9410 Fall Bioinformatics for Molecular Biology. More Unix

LOG ON TO LINUX AND LOG OFF

CS CS Tutorial 2 2 Winter 2018

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Unix System Architecture, File System, and Shell Commands

Software I: Utilities and Internals. What is UNIX?

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois

Transcription:

The Unix Shell Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.

shell

shell pwd mkdir cd nano ls rm. rmdir.. mv cp

shell pwd mkdir cd nano ls rm. rmdir.. mv cp More powerful when combined

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb * is a wild card

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb * is a wild card matches zero or more characters

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb * is a wild card matches zero or more characters so *.pdb matches all filenames ending in.pdb

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb wc cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb word count

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb word count counts lines, words, and characters in files

$ ls molecules cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb $ cd molecules $ wc *.pdb $ 20 156 1158 cubane.pdb 12 84 622 ethane.pdb 9 57 422 methane.pdb 30 246 1828 octane.pdb 21 165 1226 pentane.pdb 15 111 825 propane.pdb 107 819 6081 total

$ wc -l *.pdb 20 cubane.pdb 12 ethane.pdb 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total $ report only lines

$ wc -l *.pdb 20 cubane.pdb 12 ethane.pdb 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total $ report only lines use -w for words or -c for characters

20 cubane.pdb 12 ethane.pdb 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total Which file is shortest?

20 cubane.pdb 12 ethane.pdb 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total Which file is shortest? Easy to see when there are six

20 cubane.pdb 12 ethane.pdb 9 methane.pdb Which file is shortest? Easy to see when there are six 30 octane.pdb but what if there were 6000? 21 pentane.pdb 15 propane.pdb 107 total

$ wc -l *.pdb > lengths $

$ wc -l *.pdb > lengths $ redirect output to a file

$ wc -l *.pdb > lengths $ redirect output to a file create file if it doesn't exist

$ wc -l *.pdb > lengths $ redirect output to a file create file if it doesn't exist overwrite it if it does

$ wc -l *.pdb > lengths $ no screen output

$ wc -l *.pdb > lengths $ ls lengths lengths $

$ wc -l *.pdb > lengths $ ls lengths lengths $ cat lengths $ 20 cubane.pdb 12 ethane.pdb 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total

$ wc -l *.pdb > lengths $ ls lengths lengths $ cat lengths concatenate files 20 cubane.pdb 12 ethane.pdb 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total $

$ wc -l *.pdb > lengths $ ls lengths lengths $ cat lengths concatenate files 20 cubane.pdb in this case, only one 12 ethane.pdb so file contents printed to screen 9 methane.pdb 30 octane.pdb 21 pentane.pdb 15 propane.pdb 107 total $

$ sort lengths 9 methane.pdb 12 ethane.pdb 15 propane.pdb 20 cubane.pdb 21 pentane.pdb 30 octane.pdb 107 total $

$ sort lengths > sorted-lengths $

$ sort lengths > sorted-lengths $ head -1 sorted-lengths 9 methane.pdb $

$ sort lengths > sorted-lengths $ head -1 sorted-lengths 9 methane.pdb get the first line of the file $

$ sort lengths > sorted-lengths $ head -1 sorted-lengths 9 methane.pdb get the first line of the file $ this must be the PDB file with the fewest lines, since sorted-lengths holds files and line counts in order from least to greatest

$ sort lengths > sorted-lengths $ head -1 sorted-lengths 9 methane.pdb get the first line of the file $ this must be the PDB file with the fewest lines, not particularly obvious since sorted-lengths holds files and line counts in order from least to greatest

$ sort lengths head -1 $ 9 methane.pdb

$ sort lengths head -1 $ 9 methane.pdb a pipe

$ sort lengths head -1 $ 9 methane.pdb a pipe use output of left side

$ sort lengths head -1 $ 9 methane.pdb a pipe use output of left side as input to right side

$ sort lengths head -1 $ 9 methane.pdb a pipe use output of left side as input to right side without creating temporary file

$ wc -l *.pdb sort head -1 9 methane.pdb $ don't need to create lengths file

$ wc -l *.pdb sort head -1 $ 9 methane.pdb This simple idea is why Unix has been so successful

$ wc -l *.pdb sort head -1 $ 9 methane.pdb This simple idea is why Unix has been so successful Create simple tools that:

$ wc -l *.pdb sort head -1 $ 9 methane.pdb This simple idea is why Unix has been so successful Create simple tools that: do one job well

$ wc -l *.pdb sort head -1 $ 9 methane.pdb This simple idea is why Unix has been so successful Create simple tools that: do one job well work well with each other

$ wc -l *.pdb sort head -1 $ 9 methane.pdb This simple idea is why Unix has been so successful Create simple tools that: do one job well work well with each other 10 tools can be combined in 100 ways

running program

running program process

standard input

standard input stdin

standard output stdout

shell

$ wc -l *.pdb > lengths

wc $ wc -l *.pdb > lengths

wc $ wc -l *.pdb > lengths

wc lengths $ wc l *.pdb > lengths

wc sort $ wc l *.pdb sort

wc sort head -1 $ wc l *.pdb sort head -1

This programming model called pipes and filters

This programming model called pipes and filters A filter transforms a stream of input into a stream of output

This programming model called pipes and filters A filter transforms a stream of input into a stream of output A pipe connects two filters

This programming model called pipes and filters A filter transforms a stream of input into a stream of output A pipe connects two filters Any program that reads lines of text from standard input, and writes lines of text to standard output, can work with every other

This programming model called pipes and filters A filter transforms a stream of input into a stream of output A pipe connects two filters Any program that reads lines of text from standard input, and writes lines of text to standard output, can work with every other You can (and should) write such programs

pwd mkdir cd nano ls rm. rmdir.. mv cp

pwd mkdir wc cd nano sort ls rm head. rmdir.. mv cp

pwd mkdir wc cd nano sort ls rm head. rmdir tail.. mv split cp cut uniq

pwd mkdir wc * cd nano sort > ls rm head. rmdir tail.. mv split cp cut uniq

pwd mkdir wc * cd nano sort > ls rm head. rmdir tail <.. mv split? cp cut uniq

created by Greg Wilson August 2010 Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.