Aliases, functions, wrappers, pipelines

Slides:



Advertisements
Similar presentations
Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
Advertisements

Introduction to Linux Alan Orth April 17, 2010 ILRI, Nairobi.
It's a binary file kept under specific directory.
Find Command Characteristics –Locate files descending from multiple starting points –Employs regular expressions Examples On entire system: >find / -name.
1 Basics of Linux On linux machine: Login at your home directory Open a “shell” or “terminal” or “xterm” workspace (4) On windows machine Intall linux.
UNIX Command-line Introduction Terence Parr. Navigating  cd  pwd  ls  pushd/pod  cd  pwd  ls  pushd/pod.
Introduction to Linux and Shell Scripting Jacob Chan.
Understanding the Basics of Computational Informatics Summer School, Hungary, Szeged Methos L. Müller.
Shell Script Examples.
Unix Tutorial for FreeSurfer Users Allison Stevens.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Linux Shell Programming Tutorial 3 ENGR 3950U / CSCI 3020U Operating Systems Instructor: Dr. Kamran Sartipi.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Shell Script Yingying Wang. Basic Commands Good resources Google is your friend
Linux File System and The Shell Yonglei Tao. Linux File System  Consists of one or more self-contained file management units  each is known as a filesystem.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
L&T Infotech1 UNIX – Getting Started - Aneesh Ramani.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
40 Years and Still Rocking the Terminal!
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
Linux Stuff Last Update Copyright 2014 Kenneth M. Chipps Ph.D. 1.
The Unix File sytem. Introduction Tree structure …
Unix Fundamentals CS 127. File navigation cd - change directory cd /var/log cd /etc/apache2 cd ~/Desktop ~ is a shortcut for the home directory.
Basic Unix Commands. Listing files and directories ● ls:command is used to list the files and ● directories in present working directory ● ls command.
EMT 2390L Lecture 3 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Introduction to Unix for FreeSurfer Users
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Intro to shell scripting
CIRC Winter Boot Camp 2017 Baowei Liu
Getting started with CentOS Linux
Intro to shell scripting
Prepared by: Eng. Maryam Adel Abdel-Hady
Andy Wang Object Oriented Programming in C++ COP 3330
CSE 390a Lecture 5 Intro to shell scripting
C151 Multi-User Operating Systems
Intro to shell scripting
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
LING 408/508: Computational Techniques for Linguists
Tutorial of Unix Command & shell scriptS 5027
The Unix File System.
UNIX Reference Sheets CSE 2031 Fall 2010.
Getting started with CentOS Linux
Intro to shell scripting
Tutorial Unix Command & Makefile CIS 5027
Persistent shell settings; intro to shell scripting
The Linux Command Line Chapter 4
Linux Shell Script Programming
Intro to shell scripting
Intro to shell scripting
CSE 303 Concepts and Tools for Software Development
Module 6 Working with Files and Directories
Lab 2: Terminal Basics.
Intro to shell scripting
Introduction to Bash Programming, part 3
Intro to shell scripting
The Linux Command Line Chapter 4
Presentation transcript:

Aliases, functions, wrappers, pipelines Virginie Orgogozo April 6 2012

Alias shortcut for a commonly used shell command ~/.bash_profile or ~/.bashrc file: (…) alias cdp='cd ~/pcfb/sandbox' alias cx='chmod u+x' alias ag='agrep -B -y -d “>” ' alias myjobs=“ps -ax | grep orgogozo” alias hg='history | grep' In the shell: $cdp $cx script2.py $ag CYG examples/FPexcerpt.fta $myjobs $hg pcfb $alias (list your defined aliases) For the changes in your .bashrc file to be used in the shell: - open a new shell window or: - $source .bashrc

Functions For a more complex set of shell commands In the shell: $pdftk GenomeBiolPaper.pdf cat 2-end output Doe2012.pdf $firstpage GenomeBiolPaper.pdf Doe2012.pdf $listall ~/.bash_profile or ~/.bashrc file: (…) function firstpage() { pdftk $1 cat 2-end output $2 ;} listall() { ls -la echo “Above are all the directories of the following folder:” pwd date }

You can also write a function in the shell only virginie@Darwin:~$ repeater(){ > echo "$1 is what you said first" > echo "$@ is everything you said" > } virginie@Darwin:~$ repeater hello everybody! How are you? hello is what you said first hello everybody! How are you? is everything you said virginie@Darwin:$ Defines the function Usage of the function

Use a function when you want to use the same command multiple times with different filenames in the middle virginie@Darwin:~$ phyml sequencesA.fta 1 i 1 100 WAG 0 8 e BIONJ y y virginie@Darwin:~$ phyml sequencesB.fta 1 i 1 100 WAG 0 8 e BIONJ y y virginie@Darwin:~$ phyml CG5679.fta 1 i 1 100 WAG 0 8 e BIONJ y y virginie@Darwin:~$ phyml ASCRE.fta 1 i 1 100 WAG 0 8 e BIONJ y y (...) virginie@Darwin:~$myphyml(){ > phyml $1 1 i 1 100 WAG 0 8 e BIONJ y y > } virginie@Darwin:~$ myphyml sequencesA.fta virginie@Darwin:~$ myphyml sequencesB.fta && myphyml CG5679.fta && myphyml ASCRE.fta Defines the function Usage of the function

Use a function to rename multiple files file1.txt file2.txt file3.txt ... u_file1.dat u_file2.dat u_file3.dat ... renamer(){ EXT="dat" PRE="u_" if [ $# -lt 1 ] then echo "Rename a file.txt list as $PREfile.$EXT" else for FILENAME in "$@" do ROOTNAME="${FILENAME%.*}" cp "$FILENAME" "$PRE$ROOTNAME.$EXT" echo "Copying $FILENAME to $PRE$ROOTNAME.$EXT" done fi } (if the number of arguments is ..., then...) Copy and paste this text from pcfb/scripts/shellfunctions.sh in your shell

virginie@Darwin:~$ cd ~/pcfb/examplesspectra/ virginie@Darwin:~/pcfb/examples/spectra$ ls LEDBlue.txt LEDGreen.txt LEDRed.txt LEDYellow.txt virginie@Darwin:~/pcfb/examples/spectra$ renamer *.txt Copying LEDBlue.txt to u_LEDBlue.dat Copying LEDGreen.txt to u_LEDGreen.dat Copying LEDRed.txt to u_LEDRed.dat Copying LEDYellow.txt to u_LEDYellow.dat LEDBlue.txt LEDRed.txt u_LEDBlue.dat u_LEDRed.dat LEDGreen.txt LEDYellow.txt u_LEDGreen.dat u_LEDYellow.dat virginie@Darwin:~/Documents/WWW/BioInfoCourses/pcfb/examples/spectra$

Use a loop to repeat operations virginie@Darwin:~$for k in {1..10} >do >echo $k >done 1 2 3 4 5 6 7 8 9 10 virginie@Darwin:~$ virginie@Darwin:~$for i in {A..Z}; do mkdir $i-authors; mv $i*.pdf $i-authors; done

Wrappers Program that controls and expands the functionality of another program Ex: python script that calls MATLAB or another program Pipelines Automated workflow Very important for efficiency, consistency and record