Using the Unix Shell There is No ‘Undelete’. The Unix Shell “A Unix shell is a command-line interpreter or shell that provides a traditional user interface.

Slides:



Advertisements
Similar presentations
By: Tony Andrews.  Linux directory ordering system  Navigating and creating directories ◦ Listing directories and files ◦ Creating directories ◦ Changing.
Advertisements

Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Shell Scripting Basics Arun Sethuraman. What’s a shell? Command line interpreter for Unix Bourne (sh), Bourne-again (bash), C shell (csh, tcsh), etc Handful.
UNIX Filters.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
Review for Exam 1 Exam 1 on June 24 CSC 3320.
1 Day 16 Sed and Awk. 2 Looking through output We already know what “grep” does. –It looks for something in a file. –Returns any line from the file that.
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
The file structure and related utilities CS240 Computer Science II.
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”
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
Unix Basics Chapter 4.
A Guide to Unix Using Linux Fourth Edition
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
Unix programming Term: III B.Tech II semester Unit-II PPT Slides Text Books: (1)unix the ultimate guide by Sumitabha Das (2)Advanced programming.
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
OPERATING SYSTEMS DESIGN UNIX BASICS & SHELL SCRIPTING.
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.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
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.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Log-in to the Unix Server A successful log-in allows access to the server through the Secure Shell. SSH, also known as Secure Shocket Shell, is a Unix.
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.
Getting the most out of the workshop Ask questions!!! Don’t sit next to someone you already know Work with someone with a different skillset and different.
Introduction to Programming Using C An Introduction to Operating Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Sed. Class Issues vSphere Issues – root only until lab 3.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
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.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Linux command line basics III: piping commands for text processing
CS 403: Programming Languages
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Chapter Four UNIX File Processing.
Presentation transcript:

Using the Unix Shell There is No ‘Undelete’

The Unix Shell “A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering commands as text for a command line interpreter to execute or by creating text scripts of one or more such commands.” - Wikipedia

Things to Keep in Mind There is no ‘undelete’ Shell commands are case-sensitive (CaPitaLizaTIoN mAttErs) Do NOT use space, ?, *, \, / or $ in file names because these have special meanings to the shell Filenames that begin with. are ‘hidden’ There is no ‘undelete’

The Importance of Being ‘Root’ ‘Root’ or ‘Superuser’ is the administrator account, which has phenomenal cosmic power. The ‘sudo’ command allows you to “do as superuser” from an account with ‘sudo privileges’. As root in the shell, you can literally ‘delete’ the operating system or operating system files (like choosing to delete Microsoft Windows while using Windows)… and then watch the stars go out… – Moral of the story: If you don’t know what a file is… it’s better to ask or leave it alone. – Installing software can require use of ‘sudo’

Unix Tutorial Science.txt file location for tutorial: – – Unix command: wget Additional help/tutorial/walkthrough

Grep grep science science.txt grep science science.txt > newfile1.txt grep -B 1 -A 2 science science.txt > newfile1.txt Use man grep to learn more about grep A ‘redirect’ symbol that sends output which would normally go to the screen to a text file instead. Command line ‘options’ that change the behavior of the ‘grep’ program, with numerical parameters that specify the new behavior.

Permissions Type ls -l *note: those are both lower-case L characters -rw-r--r-- 1 krmerrill staff Feb 2 13:00 AJB_Merrill-d _au.doc drwxr-xr-x 47 krmerrill staff 1598 Jul My Pictures - means regular file, d means directory, l (lower-case L) means link first triplet is the user read, write, and execute permissions second triplet is the group permissions last triplet is permissions for everyone else, or ‘other’ ls -al shows above information for all files, including hidden files chmod = change permissions u = user; g = group; o = other;a = all (user, group, and other) r = read; w = write; x = execute chmod u+x filename adds user execute permission on filename chmod g-wx filename removes group write and execute permissions from filename Permissions that are not mentioned in this format chmod command are not affected

Useful Shell Commands See the Linux Command Line Reference document on the course website Directory commands Change to sub-directory within the current directory: cd xyz Change to sub-directory in another part of the directory tree: cd /path/to/filename Create directory: mkdir newdir Remove empty directory: rmdir xyz Wildcard characters: ? matches any single character, * matches zero or more characters Example: rm *.txt will remove all files with a name ending in.txt rm file?.fastq will remove file1.fastq, file2.fastq, …, filex.fastq

Regular Expressions See the RegularExpressions.pdf document on the course website for an overview of literal characters and metacharacters Regular expressions are useful within grep, awk, sed and other command-line tools as well as in Java, Perl, Python, and other scripting languages. Some text editor programs in Linux also use regular expressions, (also called regexps or regex). We will use nedit as an example. Replacing a space character with a new-line character in a file of barcodes – find ‘(OWB\d+) ’ and replace with ‘\1\n’ – note the trailing space in the first expression.

Command-line example Testing analyses on a small random sample of a sequence dataset is a good idea – find and fix problems quickly How to randomly sample the same reads from a set of paired- end files? A one-line command is saved on the course website to do this. time paste file1.fastq file2.fastq |awk '{ printf("%s",$0); n++; if(n%4==0) { printf("\n");} else { printf("\t\t");} }' | shuf | head | sed 's/\t\t/\n/g' | awk '{print $1 > "file1.fastq"; print $2 > "file2.fastq"}‘ Let’s look at this step by step

time this tells the system to display the time required to execute the command paste Bigfile1.fastq Bigfile2.fastq | this joins two files of paired-end sequence reads as tab-delimited columns, line by line – the files should have the same number of lines, with reads in the same order in both files awk '{ printf("%s",$0); n++; if(n%4==0) { printf("\n");} else { printf("\t\t");} }' | this uses the ‘awk’ program to convert the four lines of FASTQ format to tab-separated fields on a single line per sequence record shuf | this utility sorts lines in a file into a random order head | this utility takes the first 2 million lines of the re-ordered file sed 's/\t\t/\n/g' | this uses the ‘sed’ stream editor to convert the tab delimiters back into new-line characters to restore the 4-line FASTQ format awk '{print $1 > “Subfile1.fastq"; print $2 > “Subfile2.fastq"}' this uses ‘awk’ to split the two tab-delimited columns back into two separate files Command-line example

How do you come up with this stuff?

Someone else has probably had this problem

Search for help on SeqAnswers or StackExchange The Bioinformatics Forum on SeqAnswers:

SolexaQA.pl This Perl script assumes that header lines of sequence files are written in one of several formats The code uses regular expressions to sort out formats: if( $line =~ /\S+\s\S+/ ){# Cassava 1.8 variant if( $line =~ ){ $number_of_tiles = $1 + 1;# Sequence Read Archive variant }elsif( $line =~ ){ $number_of_tiles = $1 + 1;}# All other variants }elsif( $line =~ ){ $number_of_tiles = $1 + 1;}

Alternate Formats This Perl script assumes that header lines of sequence files are written in one of several formats The code uses regular expressions to sort out formats: if( $line =~ /\S+\s\S+/ ){# Cassava 1.8 variant – does the header line contain a space surrounded by non-space $line =~ ) # NCBI SRA variant – does the header line contain a string with –, _,or. before the first _SLXA-EAS1_s_7:5:1:817:345 length=36

SolexaQA.pl $line =~ ) # Two other variants – 1.does first field contain –,., or _ followed by two more colon- delimited fields? $line =~ ) 2.does first field contain –,., :, or _ followed by four colon-delimited fields, followed by., /, or # at the end of the line? Example header line from GSL sequence This would be described by $line =~