SlideShare una empresa de Scribd logo
1 de 28
*nix Command Line Kung Foo DevChatt, March 2010
Who is this guy? Brian Dailey realm3 web applications Nashville
Why the command line?
It is concise.
It is consistent.
It saves time.
What command line?
Posix compliant shell (Preferably bash or dash.)
Not using *nix? Pity. Mac OS X: You're good! Windows: Use cygwin (preferable)  or a Unix port such as: http://unxutils.sourceforge.net/ Other:  PuTTY + Amazon EC2, Ubuntu Live CD, etc.
Basics: Keyboard Navigation
Shell Keyboard Navigation Basics ↑↓ -  Scroll through previous commands Ctrl+U - Clear all before cursor Ctrl+K - Clear all after cursor Ctrl+A - <Home> Ctrl+E - <End> Alt+B - Move cursor back one ”word” (Similar to Ctrl+ ← ) Alt+F - Move cursor forward one ”word” (Ctrl+ -> ) Alt+Bckspc - Delete previous ”word” (Also, Ctrl+W) Alt+. - Recall last command argument Tab - Autocomplete commands, files, folders, and more. Ctrl+L - Clear the screen Ctrl+_ - Undo CTRL+R - Recall previous commands Esc, T - Swap last two words These shortcuts are nearly universal (bash, MySQL) due to use of the GNU Readline library. Exhaustive list is available here:  http://onlyubuntu.blogspot.com/2007/03/bash-shell-keyboard-shortcuts-for-linux.html
Goodbye, Mouse! Example: mysql> SELECT user.id, user.username, user.email, user.address, user.city, user.state, user.name, userfile.file_name, userfile.metadata, userfile.other_stuff  FOM  user JOIN userfiles ON user.id = userfile.user_id AND user.id BETWEEN 1 AND 100 AND user.created BETWEEN '2008-10-10' AND '2009-10-10' AND user.is_active = 1 AND user.name LIKE 'Frodo%' LIMIT 10; [] n00b: Hold backspace key for 30 seconds. Fix, retype. Good: Press Alt+B to jump backwards one word at a time. Holy Hand Grenade: Press Alt+3,0,B to jump backwards  30  words.
Shell Keyboard Navigation Kill and yank = Cut and paste Kill Commands: Ctrl+U - Kill all before cursor Ctrl+K - Kill all after cursor Alt+Bckspc – Kill previous word All kill commands place text into a buffer (aka “kill ring”). Ctrl+Y  – Yank Alt+Y   - Rotate kill ring, yank new top Technically yanks text from top of “kill ring”.  To rotate through the ring you must first yank, then press Alt+M to rotate.
Shell Keyboard Navigation Use Tab for auto-completion! $ svn ci -m”Fixed issue.” fil[tab] ↓ $ svn ci -m”Fixed issue.” filename.php [Tab][Tab] shows all available matches: $ svn ci -m”Fixed issue.” f[tab][tab] filename.php frodo_baggins.php friendly_fellow.php Enable programmable bash completion for further efficiency (compete args). $ git c[tab][tab] checkout  cherry  cherry-pick  ci  clean  clone  co  commit  config
Shell Keyboard Navigation !! - Run the last command (same as  ↑ +return) !my - Runs last cmd starting with ”my”, e.g.,  ” mysql -uroot -p db” !my:p - Find last cmd starting with ”my” and print it out vi !$  - Replaces !$ with last argument in previous command vi !* - Insert all arguments from previous command ^foo^bar - Run previous command but replace first “foo” with “bar” !!:gs/foo/bar  – Run previous command, but replace all instances  of “foo” with “bar” cd - - change to previous working directory A very useful (and more comprehensive) list is available here: http://mail.linux.ie/pipermail/ilug/2006-May/087799.html Also recommended: http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/
Shell Basics: I/O Redirect Concept can be thought of as ” pipes ” and ” streams ” Negates the need for an application to write to a file, only for another application to read it.
I/O filters less  – Interactive text pager with search capability. sort  – Sort lines (alphabetically, numerically, etc) grep  – Regular expression searches uniq  – Detect (report or omit) repeated lines sed  – Stream EDitor awk  – powerful pattern scanning and  text processing language xargs  – build and execute commands from input cut - divide into columns There are a lot more of these tools!
I/O Basic example of standard output: # format an XML file and feed it out to formatted.xml $ xmllint feed.xml --format > formatted.xml # same as above, but append to existing file. $ xmllint feed.xml --format >> formatted.xml Standard input: $ mysql -uuser -p db1 < schema.sql Or both: $ mysql -uuser -p db1 < schema.sql > log.txt Can also redirect stderr (errors). Use the pipe! $ history | grep svn
I/O Examples of pipe chaining... Colorize Subversion diff output: $  svn diff | colordiff | less -R Search files for child classes, do not include test files, sort them alphabetically, and paginate. $ grep -r -n -H '^class.*extends.*{$' * | grep -v test | sort | more
I/O Example: # copy the latest changeset to a git-less server $ git log -1 --name-status | # only get files added or modified grep '^[AM]' | # strip out status from stream sed 's/^[AM]*//' | # scp to server (one at a time), retaining path xargs -I {} scp {}  [email_address] :dir/{} (Disclaimer: There are better ways to do deploy changes.)
Holy smokes!  How will I remember to type all that?
Let's automate this stuff!
Introducing Alias alias deploy=”git log -1 --name-status | grep '^[AM]' | sed 's/^[AM]*//' | xargs -I {} scp {}  [email_address] :dir/{}” # Other Examples # List files in friendly format alias l='ls -l' # Colorize svn diff, use less -R to accept colors alias sdv='svn diff | colordiff | less -R' # Do not allow updates or deletes without a primary key alias mysql='mysql --i-am-a-dummy'
Alias Things to know: With alias, all arguments are appended to the command. Save your aliases to your .bashrc to automatically use in new sessions.
Alias # Usage: fun [name] alias fun='echo $1 is having fun!' $ fun Brian is having fun! Brian Alias is only useful as the  beginning  of a command. Arguments  don't work well, can't do loops, etc.
Shell Functions Look up PHP command arguments: phpargs() { # $1 is the first argument passed # get php page from manual mirror curl -s http://us3.php.net/$1 | # pull all text in target div sed -n '/<div class=&quot;methodsynopsis dc-description&quot;>/,/<div>/p' | # strip out HTML tags sed 's/<[^>]*>//g' | # strip out line feed tr -d &quot;&quot; # add ending line echo } Then from the command line: $ phpargs in_array bool in_array ( mixed $needle, array $haystack [, bool $strict  ] ) The only way to learn scripts is to  write  them!
Further Resources Comprehensive Introduction to the shell http://www.linuxcommand.org/learning_the_shell.php Bash keyboard shortcuts http://onlyubuntu.blogspot.com/2007/03/bash-shell-keyboard-shortcuts-for-linux.html Bash arguments http://www.deadman.org/bash.html Bash programmable completion: http://www.debian-administration.org/articles/316 http://freshmeat.net/projects/bashcompletion/ IBM Bash By Tutorial Series http://www.ibm.com/developerworks/library/l-bash.html http://www.ibm.com/developerworks/library/l-bash2.html http://www.ibm.com/developerworks/library/l-bash3.html Cat on Mat: http://catonmat.com/
Thanks! Any questions? Brian Dailey realm3 web applications Web:  http://realm3.com/ Twitter: @brian_dailey Email: brian@realm3.com/ Phone:  917-512-3594 slide-bg:  http://bit.ly/xc0m1 Kudos to: http://asi9.net/

Más contenido relacionado

La actualidad más candente

Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsDr.Ravi
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptroot_fibo
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?Lloyd Huang
 
Airlover 20030324 1
Airlover 20030324 1Airlover 20030324 1
Airlover 20030324 1Dr.Ravi
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Zyxware Technologies
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsManav Prasad
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humansJuan De Bravo
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide SummaryOhgyun Ahn
 
Unix Commands
Unix CommandsUnix Commands
Unix CommandsDr.Ravi
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash scriptSimon Su
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Aaron Zauner
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 

La actualidad más candente (20)

Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell script
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Airlover 20030324 1
Airlover 20030324 1Airlover 20030324 1
Airlover 20030324 1
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humans
 
Bash shell
Bash shellBash shell
Bash shell
 
BASH Guide Summary
BASH Guide SummaryBASH Guide Summary
BASH Guide Summary
 
Unix Commands
Unix CommandsUnix Commands
Unix Commands
 
Unix shell scripting
Unix shell scriptingUnix shell scripting
Unix shell scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 

Destacado

omnicare annual reports 2006
omnicare annual reports 2006omnicare annual reports 2006
omnicare annual reports 2006finance46
 
Brannprosjektering 01 generelle krav til sikkerhet ved brann
Brannprosjektering 01 generelle krav til sikkerhet ved brannBrannprosjektering 01 generelle krav til sikkerhet ved brann
Brannprosjektering 01 generelle krav til sikkerhet ved brannFred Johansen
 
Open Source for the greater good
Open Source for the greater goodOpen Source for the greater good
Open Source for the greater goodDavid Coallier
 
Transparency and Acountability in Project Delivery
Transparency and Acountability in Project DeliveryTransparency and Acountability in Project Delivery
Transparency and Acountability in Project DeliveryRajesh Prasad
 
Seo uisstudenter261010-1
Seo uisstudenter261010-1Seo uisstudenter261010-1
Seo uisstudenter261010-1Ingeborg Dirdal
 
Guía de lectura Finanzas 2 - 2C2012
Guía de lectura Finanzas 2 - 2C2012Guía de lectura Finanzas 2 - 2C2012
Guía de lectura Finanzas 2 - 2C2012finanzas_uca
 
hormel foods 2002_proxy
hormel foods  2002_proxyhormel foods  2002_proxy
hormel foods 2002_proxyfinance46
 
The Rise of Click Bait, Death of Quality Content, and What We Can Do About It
The Rise of Click Bait, Death of Quality Content, and What We Can Do About ItThe Rise of Click Bait, Death of Quality Content, and What We Can Do About It
The Rise of Click Bait, Death of Quality Content, and What We Can Do About ItA Better Version of You
 
Production Travels
Production Travels Production Travels
Production Travels deeppurple64
 
Jak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW Klasy
Jak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW KlasyJak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW Klasy
Jak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW Klasyzakzak
 
Ejercicio Viernes Borja Roldan
Ejercicio Viernes Borja RoldanEjercicio Viernes Borja Roldan
Ejercicio Viernes Borja Roldanborjaroldan
 
B2B Technology Marketing Benchmarks
B2B Technology  Marketing  BenchmarksB2B Technology  Marketing  Benchmarks
B2B Technology Marketing BenchmarksMediamaispasque
 

Destacado (20)

omnicare annual reports 2006
omnicare annual reports 2006omnicare annual reports 2006
omnicare annual reports 2006
 
Breaking Technologies
Breaking TechnologiesBreaking Technologies
Breaking Technologies
 
100mph, Stage 3: Flipping the Switch
100mph, Stage 3: Flipping the Switch100mph, Stage 3: Flipping the Switch
100mph, Stage 3: Flipping the Switch
 
Brannprosjektering 01 generelle krav til sikkerhet ved brann
Brannprosjektering 01 generelle krav til sikkerhet ved brannBrannprosjektering 01 generelle krav til sikkerhet ved brann
Brannprosjektering 01 generelle krav til sikkerhet ved brann
 
Open Source for the greater good
Open Source for the greater goodOpen Source for the greater good
Open Source for the greater good
 
Transparency and Acountability in Project Delivery
Transparency and Acountability in Project DeliveryTransparency and Acountability in Project Delivery
Transparency and Acountability in Project Delivery
 
Seo uisstudenter261010-1
Seo uisstudenter261010-1Seo uisstudenter261010-1
Seo uisstudenter261010-1
 
Guía de lectura Finanzas 2 - 2C2012
Guía de lectura Finanzas 2 - 2C2012Guía de lectura Finanzas 2 - 2C2012
Guía de lectura Finanzas 2 - 2C2012
 
Cbf02
Cbf02Cbf02
Cbf02
 
hormel foods 2002_proxy
hormel foods  2002_proxyhormel foods  2002_proxy
hormel foods 2002_proxy
 
CloudStack入門以前
CloudStack入門以前CloudStack入門以前
CloudStack入門以前
 
The Rise of Click Bait, Death of Quality Content, and What We Can Do About It
The Rise of Click Bait, Death of Quality Content, and What We Can Do About ItThe Rise of Click Bait, Death of Quality Content, and What We Can Do About It
The Rise of Click Bait, Death of Quality Content, and What We Can Do About It
 
Production Travels
Production Travels Production Travels
Production Travels
 
90 10 Principle
90 10 Principle90 10 Principle
90 10 Principle
 
Jak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW Klasy
Jak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW KlasyJak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW Klasy
Jak Gry Komputerowe WpłYnęłY Na RozwóJ KomputeróW Klasy
 
The Local Government Research Group
The Local Government Research GroupThe Local Government Research Group
The Local Government Research Group
 
Brochure Anon
Brochure AnonBrochure Anon
Brochure Anon
 
Clever Advertising
Clever AdvertisingClever Advertising
Clever Advertising
 
Ejercicio Viernes Borja Roldan
Ejercicio Viernes Borja RoldanEjercicio Viernes Borja Roldan
Ejercicio Viernes Borja Roldan
 
B2B Technology Marketing Benchmarks
B2B Technology  Marketing  BenchmarksB2B Technology  Marketing  Benchmarks
B2B Technology Marketing Benchmarks
 

Similar a DevChatt 2010 - *nix Cmd Line Kung Foo

Similar a DevChatt 2010 - *nix Cmd Line Kung Foo (20)

Love Your Command Line
Love Your Command LineLove Your Command Line
Love Your Command Line
 
Vim and Python
Vim and PythonVim and Python
Vim and Python
 
Unix
UnixUnix
Unix
 
Unit 6 bash shell
Unit 6 bash shellUnit 6 bash shell
Unit 6 bash shell
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Workshop on command line tools - day 1
Workshop on command line tools - day 1Workshop on command line tools - day 1
Workshop on command line tools - day 1
 
tools
toolstools
tools
 
tools
toolstools
tools
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Shell programming
Shell programmingShell programming
Shell programming
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
Linux com
Linux comLinux com
Linux com
 
unix_commands.ppt
unix_commands.pptunix_commands.ppt
unix_commands.ppt
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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.pdfhans926745
 
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 TerraformAndrey Devyatkin
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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 Processorsdebabhi2
 
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 WorkerThousandEyes
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
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.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

DevChatt 2010 - *nix Cmd Line Kung Foo

  • 1. *nix Command Line Kung Foo DevChatt, March 2010
  • 2. Who is this guy? Brian Dailey realm3 web applications Nashville
  • 8. Posix compliant shell (Preferably bash or dash.)
  • 9. Not using *nix? Pity. Mac OS X: You're good! Windows: Use cygwin (preferable) or a Unix port such as: http://unxutils.sourceforge.net/ Other: PuTTY + Amazon EC2, Ubuntu Live CD, etc.
  • 11. Shell Keyboard Navigation Basics ↑↓ - Scroll through previous commands Ctrl+U - Clear all before cursor Ctrl+K - Clear all after cursor Ctrl+A - <Home> Ctrl+E - <End> Alt+B - Move cursor back one ”word” (Similar to Ctrl+ ← ) Alt+F - Move cursor forward one ”word” (Ctrl+ -> ) Alt+Bckspc - Delete previous ”word” (Also, Ctrl+W) Alt+. - Recall last command argument Tab - Autocomplete commands, files, folders, and more. Ctrl+L - Clear the screen Ctrl+_ - Undo CTRL+R - Recall previous commands Esc, T - Swap last two words These shortcuts are nearly universal (bash, MySQL) due to use of the GNU Readline library. Exhaustive list is available here: http://onlyubuntu.blogspot.com/2007/03/bash-shell-keyboard-shortcuts-for-linux.html
  • 12. Goodbye, Mouse! Example: mysql> SELECT user.id, user.username, user.email, user.address, user.city, user.state, user.name, userfile.file_name, userfile.metadata, userfile.other_stuff FOM user JOIN userfiles ON user.id = userfile.user_id AND user.id BETWEEN 1 AND 100 AND user.created BETWEEN '2008-10-10' AND '2009-10-10' AND user.is_active = 1 AND user.name LIKE 'Frodo%' LIMIT 10; [] n00b: Hold backspace key for 30 seconds. Fix, retype. Good: Press Alt+B to jump backwards one word at a time. Holy Hand Grenade: Press Alt+3,0,B to jump backwards 30 words.
  • 13. Shell Keyboard Navigation Kill and yank = Cut and paste Kill Commands: Ctrl+U - Kill all before cursor Ctrl+K - Kill all after cursor Alt+Bckspc – Kill previous word All kill commands place text into a buffer (aka “kill ring”). Ctrl+Y – Yank Alt+Y - Rotate kill ring, yank new top Technically yanks text from top of “kill ring”. To rotate through the ring you must first yank, then press Alt+M to rotate.
  • 14. Shell Keyboard Navigation Use Tab for auto-completion! $ svn ci -m”Fixed issue.” fil[tab] ↓ $ svn ci -m”Fixed issue.” filename.php [Tab][Tab] shows all available matches: $ svn ci -m”Fixed issue.” f[tab][tab] filename.php frodo_baggins.php friendly_fellow.php Enable programmable bash completion for further efficiency (compete args). $ git c[tab][tab] checkout cherry cherry-pick ci clean clone co commit config
  • 15. Shell Keyboard Navigation !! - Run the last command (same as ↑ +return) !my - Runs last cmd starting with ”my”, e.g., ” mysql -uroot -p db” !my:p - Find last cmd starting with ”my” and print it out vi !$ - Replaces !$ with last argument in previous command vi !* - Insert all arguments from previous command ^foo^bar - Run previous command but replace first “foo” with “bar” !!:gs/foo/bar – Run previous command, but replace all instances of “foo” with “bar” cd - - change to previous working directory A very useful (and more comprehensive) list is available here: http://mail.linux.ie/pipermail/ilug/2006-May/087799.html Also recommended: http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/
  • 16. Shell Basics: I/O Redirect Concept can be thought of as ” pipes ” and ” streams ” Negates the need for an application to write to a file, only for another application to read it.
  • 17. I/O filters less – Interactive text pager with search capability. sort – Sort lines (alphabetically, numerically, etc) grep – Regular expression searches uniq – Detect (report or omit) repeated lines sed – Stream EDitor awk – powerful pattern scanning and text processing language xargs – build and execute commands from input cut - divide into columns There are a lot more of these tools!
  • 18. I/O Basic example of standard output: # format an XML file and feed it out to formatted.xml $ xmllint feed.xml --format > formatted.xml # same as above, but append to existing file. $ xmllint feed.xml --format >> formatted.xml Standard input: $ mysql -uuser -p db1 < schema.sql Or both: $ mysql -uuser -p db1 < schema.sql > log.txt Can also redirect stderr (errors). Use the pipe! $ history | grep svn
  • 19. I/O Examples of pipe chaining... Colorize Subversion diff output: $ svn diff | colordiff | less -R Search files for child classes, do not include test files, sort them alphabetically, and paginate. $ grep -r -n -H '^class.*extends.*{$' * | grep -v test | sort | more
  • 20. I/O Example: # copy the latest changeset to a git-less server $ git log -1 --name-status | # only get files added or modified grep '^[AM]' | # strip out status from stream sed 's/^[AM]*//' | # scp to server (one at a time), retaining path xargs -I {} scp {} [email_address] :dir/{} (Disclaimer: There are better ways to do deploy changes.)
  • 21. Holy smokes! How will I remember to type all that?
  • 23. Introducing Alias alias deploy=”git log -1 --name-status | grep '^[AM]' | sed 's/^[AM]*//' | xargs -I {} scp {} [email_address] :dir/{}” # Other Examples # List files in friendly format alias l='ls -l' # Colorize svn diff, use less -R to accept colors alias sdv='svn diff | colordiff | less -R' # Do not allow updates or deletes without a primary key alias mysql='mysql --i-am-a-dummy'
  • 24. Alias Things to know: With alias, all arguments are appended to the command. Save your aliases to your .bashrc to automatically use in new sessions.
  • 25. Alias # Usage: fun [name] alias fun='echo $1 is having fun!' $ fun Brian is having fun! Brian Alias is only useful as the beginning of a command. Arguments don't work well, can't do loops, etc.
  • 26. Shell Functions Look up PHP command arguments: phpargs() { # $1 is the first argument passed # get php page from manual mirror curl -s http://us3.php.net/$1 | # pull all text in target div sed -n '/<div class=&quot;methodsynopsis dc-description&quot;>/,/<div>/p' | # strip out HTML tags sed 's/<[^>]*>//g' | # strip out line feed tr -d &quot;&quot; # add ending line echo } Then from the command line: $ phpargs in_array bool in_array ( mixed $needle, array $haystack [, bool $strict ] ) The only way to learn scripts is to write them!
  • 27. Further Resources Comprehensive Introduction to the shell http://www.linuxcommand.org/learning_the_shell.php Bash keyboard shortcuts http://onlyubuntu.blogspot.com/2007/03/bash-shell-keyboard-shortcuts-for-linux.html Bash arguments http://www.deadman.org/bash.html Bash programmable completion: http://www.debian-administration.org/articles/316 http://freshmeat.net/projects/bashcompletion/ IBM Bash By Tutorial Series http://www.ibm.com/developerworks/library/l-bash.html http://www.ibm.com/developerworks/library/l-bash2.html http://www.ibm.com/developerworks/library/l-bash3.html Cat on Mat: http://catonmat.com/
  • 28. Thanks! Any questions? Brian Dailey realm3 web applications Web: http://realm3.com/ Twitter: @brian_dailey Email: brian@realm3.com/ Phone: 917-512-3594 slide-bg: http://bit.ly/xc0m1 Kudos to: http://asi9.net/