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

Similar documents
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

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Module 8 Pipes, Redirection and REGEX

ECE 364 Software Engineering Tools Lab. Lecture 2 Bash II

The input can also be taken from a file and similarly the output can be redirected to another file.

5/20/2007. Touring Essential Programs

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

The Unix Shell. Pipes and Filters

find starting-directory -name filename -user username

Consider the following program.

Common File System Commands

5/8/2012. Exploring Utilities Chapter 5

CST Algonquin College 2

Basics. I think that the later is better.

Linux Text Utilities 101 for S/390 Wizards SHARE Session 9220/5522

Reading and manipulating files

Useful Unix Commands Cheat Sheet

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

6 Redirection. Standard Input, Output, And Error. 6 Redirection

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Mineração de Dados Aplicada

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

Introduction: What is Unix?

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

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

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

Week 8 Lesson 8 03/21/18

Operating Systems. Lecture 07. System Calls, Input/Output and Error Redirection, Inter-process Communication in Unix/Linux

CSC 2500: Unix Lab Fall 2016

A Brief Introduction to the Linux Shell for Data Science

Chapter 9. Shell and Kernel

ITST Searching, Extracting & Archiving Data

Introduction to UNIX Part II

Linux II and III. Douglas Scofield. Crea-ng directories and files 18/01/14. Evolu5onary Biology Centre, Uppsala University

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

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

CS160A EXERCISES-FILTERS2 Boyd

Introduction To. Barry Grant

Advanced training. Linux components Command shell. LiLux a.s.b.l.

Sperimentazioni I LINUX commands tutorial - Part II

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

IT441. Network Services Administration. Perl: File Handles

Linux II and III. Douglas Scofield. Crea-ng directories and files 15/08/16. Evolu6onary Biology Centre, Uppsala University

UNIX, GNU/Linux and simple tools for data manipulation

bash, part 3 Chris GauthierDickey

Bash Script. CIRC Summer School 2015 Baowei Liu

Each student will work independently on several tasks. This assignment will demonstrate the student's ability to:

STATS Data Analysis using Python. Lecture 15: Advanced Command Line

CSE2031. Lab 2 FALL 2009

Review of Fundamentals

Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Recap From Last Time:

THE LINU X T H E L IN U X COMM A ND L INE

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

Scripting. More Shell Scripts Loops. Adapted from Practical Unix and Programming Hunter College

BGGN 213 Working with UNIX Barry Grant

Advanced bash scripting

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Lab 2: Linux/Unix shell

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

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

CS 246 Winter Tutorial 2

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

Linux & Shell Programming 2014

Introduction to the Shell

An Illustrated Guide to Shell Magic: Standard I/O & Redirection

CSE 15L Winter Midterm :) Review

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Pest Control. Tristan Allwood. June 13, Tristan Allwood () Pest Control June 13, / 22

Topic 2: More Shell Skills

Lecture 3 Tonight we dine in shell. Hands-On Unix System Administration DeCal

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Introduction to Unix Week 3

- c list The list specifies character positions.

Lecture 7: file I/O, more Unix

CSCI 2132 Software Development. Lecture 5: File Permissions

Lab #2 Physics 91SI Spring 2013

System Administration

Chapter 1 - Introduction. September 8, 2016

Introduction to UNIX Shell Exercises

Shell Programming Overview

INTRODUCTION TO SHELL SCRIPTING ITPART 2

Perl and R Scripting for Biologists

Introduction to UNIX command-line

Finding files and directories (advanced), standard streams, piping

UNIX Essentials Featuring Solaris 10 Op System

Linux shell scripting Getting started *

Standard File Pointers

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Introduc)on to Linux Session 2 Files/Filesystems/Data. Pete Ruprecht Research Compu)ng Group University of Colorado Boulder

CS Unix Tools. Fall 2010 Lecture 5. Hussam Abu-Libdeh based on slides by David Slater. September 17, 2010

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

Linux Tutorial #4. Redirection. Output redirection ( > )

Binghamton University. CS-211 Fall Input and Output. Streams and Stream IO

A shell can be used in one of two ways:

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

Transcription:

ULI101 Week 05

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

head and tail commands These commands display the beginning or the end of a file respectively By default, 10 lines are displayed The entire file will be displayed if it is less than 10 lines in length Example usage: head [-line_count] file for example: head 3 users.log

cut Selects fields or columns from files or standard input Range can be specified in multiple ways: 1 10 first 10 3 8 3 rd to 8 th 10 up to 10 th 2 from 2 nd until the end of line 1 3,4,10 combination of above Important options: -c cut characters Example: cut -c 1-2 will cut first 2 characters -f cut fields Example: cut f 2,5 will cut 2 nd and 5 th field

cut fields Default field delimiter is the tab Other field delimiter can be specified using the d option For example: cut d, f1 2 will cut first 2 fields delimited with a comma Field delimiter must be a single character, only one delimiter is supported If special characters are used for delimiters they must be quoted For example: cut d f1 space is the field delimiter

sort command Sorts single files or standard input Merges and sorts multiple files Is able to sort by fields Popular options: -f ignore case in comparisons -n numeric sort -u display unique entries -r reverse sort

wc Counts the number of lines, words and/or characters in a file Usage: wc option [filename] Options: -l count lines -w count words (delimited by whitespace) -m count characters If no option is specified all 3 counts are displayed

grep utility Searches for literal text and text patterns Pattern-based searches will be covered in detail next week Example usage: grep student * Works with files and/or standard input Acts like a filter outputs only lines which are successfully matched to a given regular expression A successful match can be entire line or any part of it The entire line that has the match inside will be displayed

Useful grep options -i ignores case -n numbers lines in the output -v reverse match -c displays the count of matched lines

Standard Input and Standard Output Standard input (stdin) is a general term which describes how or where a command receives information from When no information is coming from standard input a command usually has defaults or expects an argument (parameter) Typically such parameter would be a file name Standard output (stdout) describes the place where or how the commands sends its output For most commands the standard input and output are your terminal's keyboard and screen Standard input can be redirected from a file or piped from another command Standard output can be redirected to a file or piped to another command

Standard Input Redirection command < filename Example: tr a-z A-Z < ls.txt Used for commands which do not accept a file as argument

Standard Output Redirection command > filename Redirects a command's standard output to a file Stdout redirection is represented by the > symbol Example: ls > ls.txt - will save output from the ls command into a file called ls.txt If the file exists already its content will be replaced To append to a file, the >> symbol can be used

Standard Error In addition to standard input and standard output UNIX commands have standard error Standard error is the place where error messages are sent to By default error messages are sent to the terminal Standard error can be redirected by using the 2> or 2>> redirection operators Sometimes you might want to redirect the standard error to the same place as standard output Use the 2>&1 redirection for that

Inter-process communication Commands can send their standard output directly to standard input of other commands A few simple commands can form a more powerful one No temporary files are necessary This is achieved by using pipes and tees

Pipes Pipes are represented by Many commands can be piped together, but filter commands use them especially often Each filter processes the initial input based on it's design Filters must be chained in specific order Example piping use: ls less

Tee UNIX pipe with the tee utility can be used to split the flow of information Example: ls tee unsorted.txt sort ls tee sort unsorted.txt

/dev/null file The /dev/null file (sometimes called the bit bucket or black hole) is a special system file that discards all data written into in Useful to discard unwanted command output, for example: find / -name homer 2> /dev/null Also, /dev/null can provide null data (EOF only) to processes reading from it Useful to purge (empty) files etc, for example: cat /dev/null > ~/.bash_history

Here documents The << symbol indicates a here document Example: sort << EOF word name car EOF Anything between EOF EOF is sent to the standard input of a utility You can use some other string/symbol instead of EOF