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

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

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

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

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

The Unix Shell. Pipes and Filters

UNIX files searching, and other interrogation techniques

A Brief Introduction to the Linux Shell for Data Science

Lab 2: Linux/Unix shell

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

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

5/20/2007. Touring Essential Programs

CSE 303 Lecture 4. users/groups; permissions; intro to shell scripting. read Linux Pocket Guide pp , 25-27, 61-65, , 176

Practical Session 0 Introduction to Linux

Files and Directories

CSCI 2132 Software Development. Lecture 4: Files and Directories

Scripting Languages Course 1. Diana Trandabăț

CSE 15L Winter Midterm :) Review

Perl and R Scripting for Biologists

5/8/2012. Exploring Utilities Chapter 5

Filesystem and common commands

Computer Systems and Architecture

UNIX System Programming Lecture 3: BASH Programming

Introduction to Unix: Fundamental Commands

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

Computer Systems and Architecture

Chapter-3. Introduction to Unix: Fundamental Commands

CSE 390a Lecture 1. introduction to Linux/Unix environment

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

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

CSE 391 Lecture 1. introduction to Linux/Unix environment

bash, part 3 Chris GauthierDickey

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

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

A Brief Introduction to Unix

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

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

Introduction: What is Unix?

CSE 391 Lecture 1. introduction to Linux/Unix environment

CSC209H Lecture 1. Dan Zingaro. January 7, 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

Laboratory 1 Semester 1 11/12

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

Common File System Commands

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

System Administration

Introduction to UNIX command-line

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

Chapter 1 - Introduction. September 8, 2016

Files

The landscape. File hierarchy overview. A tree structure of directories The directory tree is standardized. But varies slightly among distributions

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Introduction To. Barry Grant

CST Algonquin College 2

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

Unix Tutorial Haverford Astronomy 2014/2015

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Useful Unix Commands Cheat Sheet

Module 8 Pipes, Redirection and REGEX

Parts of this tutorial has been adapted from M. Stonebank s UNIX Tutorial for Beginners (

Linux Command Line Interface. December 27, 2017

Week 2 Lecture 3. Unix

Linux Command Line Primer. By: Scott Marshall

LAB 8 (Aug 4/5) Unix Utilities

LAB 8 (Aug 4/5) Unix Utilities

Reading and manipulating files

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

CSC209. Software Tools and Systems Programming.

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Chapter 4. Unix Tutorial. Unix Shell

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

CS197U: A Hands on Introduction to Unix

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Introduction to Linux. Fundamentals of Computer Science

Utilities. September 8, 2015

Introduction to Linux

Shells and Shell Programming

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Introduction to Linux. Roman Cheplyaka

Introduction to Linux

Recap From Last Time:

Lec 1 add-on: Linux Intro

Introduction to Linux Organizing Files

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Multiple Choice - 58 Questions - 10 of 15%

BGGN 213 Working with UNIX Barry Grant

(a) About Unix. History

CENG 334 Computer Networks. Laboratory I Linux Tutorial

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

EECS2301. Lab 1 Winter 2016

Command Line Interface The basics

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

unix intro Documentation

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

Overview of the UNIX File System. Navigating and Viewing Directories

CS197U: A Hands on Introduction to Unix

Introduction to Linux

Basics. I think that the later is better.

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

Transcription:

1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson http://www.cs.washington.edu/390a/

2 Lecture summary Unix file system structure Commands for file manipulation, examination, searching Java compilation: using parameters, input, and streams Redirection and Pipes

directory Unix file system description / root directory that contains all others (drives do not have letters in Unix) /bin /dev /etc /home /media, /mnt,... /proc /tmp, /var /usr programs hardware devices system configuration files /etc/passwd stores user info /etc/shadow stores passwords users' home directories drives and removable disks that have been "mounted" for use on this computer currently running processes (programs) temporary files user-installed programs 3

Links command ln unlink description create a link to a file remove a link to a file hard link: Two names for the same file. $ ln foo bar the above command links bar as a duplicate name for foo if one is modified, the other is too; follows file moves soft (symbolic) link: A reference to another existing file. $ ln -s foo bar the above command creates a reference bar to the file foo bar can be used as though it were foo but if bar is deleted, foo will be unaffected 4

5 File examination command cat more or less head, tail wc du diff description output a file's contents on the console output a file's contents, one page at a time output the first or last few lines of a file count words, characters, and lines in a file report disk space used by a file(s) compare two files and report differences Let s explore what we can do here

6 Searching and sorting command grep sort uniq find locate which description search a file for a given string convert an input into a sorted output by lines strip duplicate (adjacent) lines search for files within a given directory search for files on the entire system shows the complete path of a command grep is actually a very powerful search tool; more later... Exercise : Given a text file names.txt, display the students arranged by the reverse alphabetical order of their names.

7 Keyboard shortcuts key Up arrow ^KEY means hold Ctrl and press KEY repeat previous commands description Home/End or ^A/^E move to start/end of current line " quotes surround multi-word arguments and arguments containing special characters * "wildcard", matches any files; can be used as a prefix, suffix, or partial name Tab ^C or ^\ ^D ^Z ^S auto-completes a partially typed file/command name terminates the currently running process end of input; used when a program is reading input from your keyboard and you are finished typing suspends (pauses) the currently running process don't use this; hides all output until ^Q is pressed

8 Programming command description javac ClassName.java compile a Java program java ClassName python, perl, ruby, gcc, sml,... run a Java program compile or run programs in various other languages Exercise : Write/compile/run a program that prints "Hello, world!" $ javac Hello.java $ java Hello Hello, world! $

9 Programming Creating parameter input to programs String[] args holds any provided parameters Exercise: modify hello world to use parameters Parameters not the same as the input stream! Exercise: modify hello world to also use a Scanner to grab input Let s revisit the standard streams

Streams in the Shell Stdin, stdout, stderr These default to the console Some commands that expect an input stream will thus read from the console if you don t tell it otherwise. Example: grep hi What happens? Why? We can change the default streams to something other than the console via redirection. 10

Output redirection command > filename run command and write its output to filename instead of to console; think of it like an arrow going from the command to the file... if the file already exists, it will be overwritten (be careful) >> appends rather than overwriting, if the file already exists command > /dev/null suppresses the output of the command Example: Example: Example: ls -l > myfiles.txt java Foo >> Foo_output.txt cat > somefile.txt (writes console input to the file until you press ^D) 11

Input redirection command < filename run command and read its input from filename instead of console whenever the program prompts the user to enter input (such as reading from a Scanner in Java), it will instead read the input from a file some commands don't use this; they accept a file name as an argument Example: java Guess < input.txt Exercise: run hello world with the input stream as a file instead of the console Exercise: Also change the output stream to write the results to file again note that this affects user input, not parameters useful with commands that can process standard input or files: e.g. grep, more, head, tail, wc, sort, uniq, write 12

Combining commands command1 command2 run command1 and send its console output as input to command2 very similar to the following sequence: command1 > filename command2 < filename rm filename Examples: diff students.txt names.txt less sort names.txt uniq Exercise : names.txt contains CSE student first names, one per line. We are interested in students whose names contain a capital "A", such as Alisa". Find out of how names containing "A" are in the file. Then figure out how many characters long the name of the last student whose name contains "A" is when looking at the names alphabetically. 13

Misusing pipes and cat Why doesn't this work to compile all Java programs? ls *.java javac Misuse of cat bad: cat filename command good: command < filename bad: good: bad: good: cat filename more more filename command cat command 14

Commands in sequence command1 ; command2 run command1 and then command2 afterward (they are not linked) command1 && command2 run command1, and if it succeeds, runs command2 afterward will not run command2 if any error occurs during the running of 1 Example: Make directory songs and move my files into it. mkdir songs && mv *.mp3 songs 15