2.0.0.3 – Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 1 2.0.0.3.3 Introduction to the Shell – Session 3 · Job control · Start,

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
A Guide to Unix Using Linux Fourth Edition
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.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to UNIX GPS Processing and Analysis with GAMIT/GLOBK/TRACK T. Herring, R. King. M. Floyd – MIT UNAVCO, Boulder - July 8-12, 2013 Directory.
CSCI 330 T HE UNIX S YSTEM File operations. OPERATIONS ON REGULAR FILES 2 CSCI The UNIX System Create Edit Display Contents Display Contents Print.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Introduction to UNIX/Linux Exercises Dan Stanzione.
Advanced File Processing
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Guide To UNIX Using Linux Fourth Edition
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
Dedan Githae, BecA-ILRI Hub Introduction to Linux / UNIX OS MARI eBioKit Workshop; Nov , 2014.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter Eight Exploring the UNIX Utilities. 2 Lesson A Using the UNIX Utilities.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
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.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
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.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Process Control. Module 11 Process Control ♦ Introduction ► A process is a running occurrence of a program, including all variables and other conditions.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Guide To UNIX Using Linux Third Edition Chapter 8: Exploring the UNIX/Linux Utilities.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Introduction to Unix (CA263) File Processing (continued) By Tariq Ibn Aziz.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Searching and Sorting. Why Use Data Files? There are many cases where the input to the program may come from a data file.Using data files in your programs.
40 Years and Still Rocking the Terminal!
Chapter Six Introduction to Shell Script Programming.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
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.
Filters and Utilities. Notes: This is a simple overview of the filtering capability Some of these commands are very powerful ▫Only showing some of the.
Lesson 5-Exploring Utilities
Chapter 11 Command-Line Master Class
...looking a bit closer under the hood
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
The UNIX Shell Learning Objectives:
Some Linux Commands.
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Chapter 6 Filters.
Linux command line basics III: piping commands for text processing
Unix Scripting Session 4 March 27, 2008.
Shell Script Assignment 1.
Introduction to UNIX Directory structure and navigation
CSE 374 Programming Concepts & Tools
Hands On UNIX AfNOG X Cairo, Egypt
Basic UNIX OLC Training.
Guide To UNIX Using Linux Third Edition
CSE 303 Concepts and Tools for Software Development
LPI Linux Certification
Presentation transcript:

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start, stop and monitor running processes · Monitoring disk usage · Command line tools · grep, cut, sort, uniq, paste, fold, tr, head, tail… · Command line Perl · When command line tools don’t quite do it

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 2 Seeing Running Processes: top · See a constantly updated list of what’s running with · Sorted by CPU use · Also shows available memory and processors · Processes can be controlled based on the PID (process ID) top Overall memory use Overall CPU use Process memory use Process CPU use I’m not running all that! Many processes are run by the OS (as user “root”) in the background. These processes generally have very low PIDs.

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 3 Seeing Running Processes: ps · See a complete list of what’s running with · By default only shows what you are running (no root or other user’s processes) · Can select which processes to show: eg. Uby user pby PID ronly running processes · See full list of everything running with ps auxw ps

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 4 Seeing Running Jobs: jobs · See currently running jobs with · These are processes that the current user is running in this terminal (does not show other user’s processes, or jobs started from other terminal windows) · Useful for job control…. jobs

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 5 Putting Processes in the Background: &, bg and fg · What if you’re running a long job (eg. BLAST), but you want to use your prompt at the same time? · Put the job in the background by starting it with & · Or, once the job is running, stop it with Cntl-Z (interrupts but does not kill), then use · To put the job back in the foreground (and lose your prompt), use · To specify which job to fg or bg, use the PID or % fg bg Job ID

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 6 Ending Jobs: Cntl-C, kill · To end (without saving anything) a job currently running in the terminal, use Cntl-C · To kill a job that is running in the background or from another terminal, use · If it really won’t die, try kill -9 but only as a last resort! Killing applications If you are running applications (eg. word processors, web browsers) from the command line, do NOT kill them unless you cannot exit the application normally – this can corrupt files or cause application errors. kill

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 7 Sharing the CPU: nice · Jobs are assigned priority (the lower the number, the higher the priority) which determines sharing of CPU · Set the priority of your job lower when running intensive jobs so that others can use the CPU too with · Or, for running jobs, with nice renice Priority Niced

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 8 Memory and Swap · Nice does not control memory use · When running memory-intensive jobs, avoid requiring swap (virtual memory – actually disk space) as this will slow all jobs on that computer

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 9 Checking Disk Location and Usage: df · To confirm that the disk you are on has enough space for you to create large files: -h human-readable df

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 10 Determining Disk Space Usage: du · To check total space taken by a directory structure, use · Find out what is taking up all your disk space! -hhuman-readable -cproduce total --max-depthonly print totals for this deep in directory tree du Saving space Cut down on disk usage by using du and find to find large, old files, and use gzip to compress them.

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 11 Working with Text · Simple text processing is a large part of bioinformatics · Converting between program formats · Data processing · Command line tools are a fast and easy way to do a lot of text processing · Usually faster than Perl · Don’t require any coding!

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 12 Searching for Text: grep · Search for text in a file with · Prints matching lines · Can do regular expression matching (slightly different from Perl) · Useful options: -icase-insensitive -wtext must appear as a “word” (surrounded by white space) -vfind non-matching lines -ccount matching lines -B print # lines before matching lines -A print # lines after matching lines -f find lines matching patterns listed in grep

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 13 Sorting Text: sort · Sort a file using · Useful options: -fcase-insensitive -gsort numerically (i.e. 11<100) -rreverse sort -k sort on column # -u only print one copy of unique lines sort

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 14 Working with Columns: cut and paste · Get particular columns from a file with · Have to specify which field (column) to get · Useful options: -f fields to output -dfield delimiter · Put columns back together with cut paste

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 15 Finding Unique or Repeated Lines: uniq · Determine unique lines with · Collapses repeated lines · Useful options: -icase insensitive -ccount copies of each line -dprint only duplicated lines -uprint only unique lines -f do not compare the first # fields uniq Pipe it! The UNIX text tools are particularly powerful in combination – use pipes to do a series of processing commands on your text.

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 16 Counting: wc · Count lines, words, and characters with · Good for checking if files have correct number of records · Useful in combination with other commands wc linesword s bytes (characte rs) How many SAGE tags match more than one gene

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 17 Replacing Characters: tr · Replace characters with · Like Perl’s tr/// · Useful options: -ddelete -sreplace repeats with single occurrence -cuse complement (replace everything EXCEPT what is specified) tr Input to tr Instead of reading from a file, tr reads from standard input. If you want it to read from a file, redirect that file to standard input with “<“, or use cat and pipe the output to tr. Format comma-separated list Capitalize

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 18 Formatting Text: fold · To wrap long lines in a file, use · Good for formatting before printing text files · Useful options: -wwidth to wrap to -sbreak at spaces fold

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 19 Getting Parts of Files: head and tail · Print the first 10 lines with · Print the last 10 lines with · Specify how many lines to get with head eg. head > gets first 100 lines · Good for making smaller “test” files head tail Divide a file into three Make a test file

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 20 Comparing files: diff · Find differences between lines in files with · Can also compare directories · Useful options: -bignore differences in white space -iignore changes in case diff Confirm file copying

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 21 More advance processing: sed and awk · Simple programming languages · Designed for command-line use · Good for more advanced text processing · But I prefer….

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session 3 22 Command Line Perl · Perl can be run on a script, or directly on text input at the command line (a very short Perl script that does not have to be saved to disk) · Input file with cat or < · Options to use command line: -efind code on command line not in file -nrun command line script on each line of input · Check out other Perl command line options with man perlrun “What?” ‘Quotes?’ When running Perl on the command line, use single quotes (‘) so that the shell does not try to interpret the Perl commands. Within these quotes, you can then use double quotes (“) for eg. print statements.

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Now you know…. · How to control your processes · How to keep up on system usage · How to play with text on the command line · How to run Perl from the command line

– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Further Readings · Job control · Linux Cookbook Ch. 4.3 · Learning the UNIX Operating System Ch. 6 · Command line goodies · Linux Cookbook Ch.13.1, · Command line Perl · Linux Cookbook Ch. 13.5, 15.5