SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Bash Shell Tips and Tricks
John, Mark, Brian, Michael, Ken, Lisa
Interactive shell puzzle 1
You just typed
$ ls –l policy.py stats.py ui_common.py

Count lines of the last file and make a .bak copy of it using
less than 20 keystrokes (no mouse, repeat key counts)
Interactive shell answer 1
You just typed
$ ls –l policy.py stats.py ui_common.py

Count lines of the last file and make a .bak copy of it using
less than 20 keystrokes (no mouse, repeat key counts):
$ wc !$
$ cp !$ !$.bak

or

$ cp !${,.bak}
Interactive shell puzzle 2
You just typed
$ ls –l policy.py rats.py ui_common.py

Correct rats.py to stats.py using 6 keystrokes (no mouse,
repeat key counts)
Interactive shell answer 2
You just typed
$ ls –l policy.py rats.py ui_common.py

Correct rats.py to stats.py using 6 keystrokes (no mouse,
repeat key counts):
$ ^r^st
Bash conditional
if [[ -d $x ]]
then
cd $x
make
cd ..
fi
Bash conditional - improved
if [[ -d “$x” ]]
then
( cd $x ; make )
fi
Bash conditional - alternate
[[ -d “$x” ]] &&
( cd $x ; make )
Bash iteration
for x in *.reclist
do
sort $x > $x.sorted
done
Bash iteration with break
for x in *.reclist
do
[[ -d “$x” ]] &&
break
sort $x > $x.sorted
done
Bash iteration - interactive
$ for x in *.reclist
> do
>
[[ -d “$x” ]] && break
>
sort $x > $x.sorted
> done
Bash variables
Default values
if [[ $i < ${max=100} ]] ...
Arithmetic
let n=2+2*3 n++ n*=3; echo $n
((n=(1+2))); echo $n  3
But
x=4; x+=6; echo $x  46

 27
Michael McKinnon’s trick
For Windows users, to dynamically change the
hover over value to reflect the machine you’re
logged into (eg, via Putty):
PROMPT_COMMAND=
'echo -ne "033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}007"'
Brian’s tricks
http://www.tldp.org/LDP/abs/html/
set –u exits on undefined variables
set –e exit immediately if a command exits with
a non-zero status
set –x echo commands before execution
use functions
pwd -P
Ken’s tricks
while read p; do
echo $p
done < peptides.txt
set –x; trap read debug

Weitere ähnliche Inhalte

Was ist angesagt?

Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
Anderson Dantas
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
Paul Lam
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
pugpe
 

Was ist angesagt? (20)

Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
Hash table and heaps
Hash table and heapsHash table and heaps
Hash table and heaps
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
 
Simplifying code monster to elegant in n 5 steps
Simplifying code  monster to elegant in n 5 stepsSimplifying code  monster to elegant in n 5 steps
Simplifying code monster to elegant in n 5 steps
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
 
Quick reference for Grafana
Quick reference for GrafanaQuick reference for Grafana
Quick reference for Grafana
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
 
ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.ggplot2 extensions-ggtree.
ggplot2 extensions-ggtree.
 
PHP 101
PHP 101 PHP 101
PHP 101
 
Plot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,onPlot3D Package and Example in R.-Data visualizat,on
Plot3D Package and Example in R.-Data visualizat,on
 
Elixir pattern matching and recursion
Elixir pattern matching and recursionElixir pattern matching and recursion
Elixir pattern matching and recursion
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
Closures
ClosuresClosures
Closures
 
py_AutoMapMaker
py_AutoMapMakerpy_AutoMapMaker
py_AutoMapMaker
 
Javascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para IniciantesJavascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para Iniciantes
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
 

Andere mochten auch

Треугольник продаж от кузнецова сергея
Треугольник продаж от кузнецова сергеяТреугольник продаж от кузнецова сергея
Треугольник продаж от кузнецова сергея
Сергей Кузнецов
 
Supporting Data-Rich Research on Many Fronts
Supporting Data-Rich Research on Many FrontsSupporting Data-Rich Research on Many Fronts
Supporting Data-Rich Research on Many Fronts
John Kunze
 
VistaNational Resource Library
VistaNational Resource LibraryVistaNational Resource Library
VistaNational Resource Library
rrobatzek
 
тренинг по продукту от кузнецова сергея
тренинг по продукту от кузнецова сергеятренинг по продукту от кузнецова сергея
тренинг по продукту от кузнецова сергея
Сергей Кузнецов
 
Bash shell
Bash shellBash shell
Bash shell
xylas121
 
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
WE-IT TUTORIALS
 

Andere mochten auch (20)

Art
ArtArt
Art
 
CV Estela Rojas 2
CV Estela Rojas 2CV Estela Rojas 2
CV Estela Rojas 2
 
Nomina compu
Nomina compuNomina compu
Nomina compu
 
Треугольник продаж от кузнецова сергея
Треугольник продаж от кузнецова сергеяТреугольник продаж от кузнецова сергея
Треугольник продаж от кузнецова сергея
 
Supporting Data-Rich Research on Many Fronts
Supporting Data-Rich Research on Many FrontsSupporting Data-Rich Research on Many Fronts
Supporting Data-Rich Research on Many Fronts
 
Future-Proofing the Web: What We Can Do Today
Future-Proofing the Web: What We Can Do TodayFuture-Proofing the Web: What We Can Do Today
Future-Proofing the Web: What We Can Do Today
 
VistaNational Resource Library
VistaNational Resource LibraryVistaNational Resource Library
VistaNational Resource Library
 
тренинг по продукту от кузнецова сергея
тренинг по продукту от кузнецова сергеятренинг по продукту от кузнецова сергея
тренинг по продукту от кузнецова сергея
 
Equipo 2 diabetes en el embarazo
Equipo 2  diabetes en el embarazoEquipo 2  diabetes en el embarazo
Equipo 2 diabetes en el embarazo
 
Licão 14 debug script
Licão 14 debug scriptLicão 14 debug script
Licão 14 debug script
 
Licão 02 shell basics bash intro
Licão 02 shell basics bash introLicão 02 shell basics bash intro
Licão 02 shell basics bash intro
 
Append 03 bash beginners guide
Append 03 bash beginners guideAppend 03 bash beginners guide
Append 03 bash beginners guide
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 
Linux Training Center Pune
Linux Training Center PuneLinux Training Center Pune
Linux Training Center Pune
 
Bash shell
Bash shellBash shell
Bash shell
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
tybsc it sem 5 Linux administration notes of unit 1,2,3,4,5,6 version 3
 

Ähnlich wie Selected Bash shell tricks from Camp CDL breakout group

Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
Ian Bishop
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
kayalkarnan
 

Ähnlich wie Selected Bash shell tricks from Camp CDL breakout group (20)

An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Tres Gemas De Ruby
Tres Gemas De RubyTres Gemas De Ruby
Tres Gemas De Ruby
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Bash Scripting
Bash ScriptingBash Scripting
Bash Scripting
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQ
 
lldb – Debugger auf Abwegen
lldb – Debugger auf Abwegenlldb – Debugger auf Abwegen
lldb – Debugger auf Abwegen
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
The Art of Command Line (2021)
The Art of Command Line (2021)The Art of Command Line (2021)
The Art of Command Line (2021)
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 

Mehr von John Kunze

DataONE Preservation and Metadata Working Group Report 2014
DataONE Preservation and Metadata Working Group Report 2014DataONE Preservation and Metadata Working Group Report 2014
DataONE Preservation and Metadata Working Group Report 2014
John Kunze
 
The Data Management Ecosystem
The Data Management EcosystemThe Data Management Ecosystem
The Data Management Ecosystem
John Kunze
 
Library Tools Supporting Data-Rich Research
Library Tools Supporting Data-Rich ResearchLibrary Tools Supporting Data-Rich Research
Library Tools Supporting Data-Rich Research
John Kunze
 
Big Data's Long Tail
Big Data's Long TailBig Data's Long Tail
Big Data's Long Tail
John Kunze
 
Scalable Identifiers for Natural History Collections
Scalable Identifiers for Natural History CollectionsScalable Identifiers for Natural History Collections
Scalable Identifiers for Natural History Collections
John Kunze
 
New Metaphors: Data Papers and Data Citations
New Metaphors: Data Papers and Data CitationsNew Metaphors: Data Papers and Data Citations
New Metaphors: Data Papers and Data Citations
John Kunze
 
Pairtrees for object storage
Pairtrees for object storagePairtrees for object storage
Pairtrees for object storage
John Kunze
 

Mehr von John Kunze (20)

The YAMZ Metadictionary
The YAMZ MetadictionaryThe YAMZ Metadictionary
The YAMZ Metadictionary
 
YAMZ Metadata Vocabulary Builder
YAMZ Metadata Vocabulary BuilderYAMZ Metadata Vocabulary Builder
YAMZ Metadata Vocabulary Builder
 
The ARK Alliance: 20 years, 850 institutions, 8.2 billion persistent identifi...
The ARK Alliance: 20 years, 850 institutions, 8.2 billion persistent identifi...The ARK Alliance: 20 years, 850 institutions, 8.2 billion persistent identifi...
The ARK Alliance: 20 years, 850 institutions, 8.2 billion persistent identifi...
 
EZID and N2T at CDL
EZID and N2T at CDLEZID and N2T at CDL
EZID and N2T at CDL
 
YAMZ.net: better, faster, cheaper taxonomy building
YAMZ.net:  better, faster, cheaper taxonomy buildingYAMZ.net:  better, faster, cheaper taxonomy building
YAMZ.net: better, faster, cheaper taxonomy building
 
A Vocabulary for Persistence
A Vocabulary for PersistenceA Vocabulary for Persistence
A Vocabulary for Persistence
 
Identifiers obey Resolvers not Schemes
Identifiers obey Resolvers not SchemesIdentifiers obey Resolvers not Schemes
Identifiers obey Resolvers not Schemes
 
Names, Things, and Open Identifier Infrastructure: N2T and ARKs
Names, Things, and Open Identifier Infrastructure: N2T and ARKsNames, Things, and Open Identifier Infrastructure: N2T and ARKs
Names, Things, and Open Identifier Infrastructure: N2T and ARKs
 
ARK identifiers: lessons learnt at BnF: paths forward
ARK identifiers: lessons learnt at BnF: paths forwardARK identifiers: lessons learnt at BnF: paths forward
ARK identifiers: lessons learnt at BnF: paths forward
 
YAMZ: a cross-domain crowd-sourced metadata vocabulary
YAMZ: a cross-domain crowd-sourced metadata vocabularyYAMZ: a cross-domain crowd-sourced metadata vocabulary
YAMZ: a cross-domain crowd-sourced metadata vocabulary
 
DataONE Preservation and Metadata Working Group Report 2014
DataONE Preservation and Metadata Working Group Report 2014DataONE Preservation and Metadata Working Group Report 2014
DataONE Preservation and Metadata Working Group Report 2014
 
Annotating Research Datasets
Annotating Research DatasetsAnnotating Research Datasets
Annotating Research Datasets
 
The Data Management Ecosystem
The Data Management EcosystemThe Data Management Ecosystem
The Data Management Ecosystem
 
Library Tools Supporting Data-Rich Research
Library Tools Supporting Data-Rich ResearchLibrary Tools Supporting Data-Rich Research
Library Tools Supporting Data-Rich Research
 
Big Data's Long Tail
Big Data's Long TailBig Data's Long Tail
Big Data's Long Tail
 
Pamwg 2012ahm
Pamwg 2012ahmPamwg 2012ahm
Pamwg 2012ahm
 
Scalable Identifiers for Natural History Collections
Scalable Identifiers for Natural History CollectionsScalable Identifiers for Natural History Collections
Scalable Identifiers for Natural History Collections
 
The ARK Identifier Scheme at Ten Years Old
The ARK Identifier Scheme at Ten Years OldThe ARK Identifier Scheme at Ten Years Old
The ARK Identifier Scheme at Ten Years Old
 
New Metaphors: Data Papers and Data Citations
New Metaphors: Data Papers and Data CitationsNew Metaphors: Data Papers and Data Citations
New Metaphors: Data Papers and Data Citations
 
Pairtrees for object storage
Pairtrees for object storagePairtrees for object storage
Pairtrees for object storage
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Selected Bash shell tricks from Camp CDL breakout group

  • 1. Bash Shell Tips and Tricks John, Mark, Brian, Michael, Ken, Lisa
  • 2. Interactive shell puzzle 1 You just typed $ ls –l policy.py stats.py ui_common.py Count lines of the last file and make a .bak copy of it using less than 20 keystrokes (no mouse, repeat key counts)
  • 3. Interactive shell answer 1 You just typed $ ls –l policy.py stats.py ui_common.py Count lines of the last file and make a .bak copy of it using less than 20 keystrokes (no mouse, repeat key counts): $ wc !$ $ cp !$ !$.bak or $ cp !${,.bak}
  • 4. Interactive shell puzzle 2 You just typed $ ls –l policy.py rats.py ui_common.py Correct rats.py to stats.py using 6 keystrokes (no mouse, repeat key counts)
  • 5. Interactive shell answer 2 You just typed $ ls –l policy.py rats.py ui_common.py Correct rats.py to stats.py using 6 keystrokes (no mouse, repeat key counts): $ ^r^st
  • 6. Bash conditional if [[ -d $x ]] then cd $x make cd .. fi
  • 7. Bash conditional - improved if [[ -d “$x” ]] then ( cd $x ; make ) fi
  • 8. Bash conditional - alternate [[ -d “$x” ]] && ( cd $x ; make )
  • 9. Bash iteration for x in *.reclist do sort $x > $x.sorted done
  • 10. Bash iteration with break for x in *.reclist do [[ -d “$x” ]] && break sort $x > $x.sorted done
  • 11. Bash iteration - interactive $ for x in *.reclist > do > [[ -d “$x” ]] && break > sort $x > $x.sorted > done
  • 12. Bash variables Default values if [[ $i < ${max=100} ]] ... Arithmetic let n=2+2*3 n++ n*=3; echo $n ((n=(1+2))); echo $n  3 But x=4; x+=6; echo $x  46  27
  • 13. Michael McKinnon’s trick For Windows users, to dynamically change the hover over value to reflect the machine you’re logged into (eg, via Putty): PROMPT_COMMAND= 'echo -ne "033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}007"'
  • 14. Brian’s tricks http://www.tldp.org/LDP/abs/html/ set –u exits on undefined variables set –e exit immediately if a command exits with a non-zero status set –x echo commands before execution use functions pwd -P
  • 15. Ken’s tricks while read p; do echo $p done < peptides.txt set –x; trap read debug