SlideShare a Scribd company logo

Love Your Command Line

Liz Henry
Liz Henry
Liz HenryFirefox Release Manager at Mozilla

Brief hands on tutorial on using the command line. Presentation from BlogHer Geek Lab and She's Geeky. Beginning commands

Love Your Command Line

1 of 12
Download to read offline
Stupid Unix Tricks or Love Your Command Line! Liz Henry BlogHer 2009
The command line is like your trusty robot friend always waiting for you to tell it what to do! How do I get to the command line? MacOS or Linux: Terminal Windows:  HyperTerminal or PuTTY, CygWin You can get these slides from my blog or we'll download them at end of session, so don't worry about taking notes!
Navigation: Where are you? pwd Print(current) working directory ls “list” files in the directory you're in. Type this a lot! cd  change directory  (blank will take you to your home dir) mkdir dev  Make a directory called “dev” in your current working directory cd dev change into that directory! whee! ls What's in there? Probably nothing since you just made it. pwd where are you again?  up arrow key Push it a few times. It shows the commands you last typed.
Navigation: Where are you? echo $SHELL What command line shell am I in? tcsh, csh, bash? whoami So existential!  What's my username? hostname What's the name of the computer or server I'm on? ping google.com  Are you on the net?  (Control-C to stop this) ifconfig  Really, how about that network!? Cryptic... traceroute google.com Where am I really? In relation to somewhere else? easy challenge:  Poke around and see what other environment  variables  you can echo! Hint, type “printenv” harder challenge: change your  prompt  to be in color and tell you what directory you're in (look up later and try it)
Look around some more! man ps alias woman=”man” alias wom=”man” wom ls  Q to quit reading man pages alias ls = “ls -lah” ps  ps -x  Whoa! ps -x | more Pipes the output into a paging program Q to quit ps -x | grep Term Pipe into “grep” to search for specific process top Info about top processes  (Q to quit)
Get remote files First use curl or wget to download two sample text files. curl -O http://bookmaniac.org/stuff/slides/example.tar.zip or  wget  http://bookmaniac.org/stuff/slides/example.tar.zip ls There's the file, tarred and zipped up tar -xvzf example.tar.zip  Uncompress the files! ls Reassure yourself... cat bloglist.txt Take a look at the file contents cat stats.txt ls -lahFSr Fancy! sorts by file size.  Challenge for later:  Download Wordpress and unzip it from the command line Download some WP themes and unzip them!  Challenge: Download and install wget if you don't have it.  Then, try downloading an entire web site with its files and images 2 levels deep: wget --wait=9 --recursive --level=2  http://example.org/

Recommended

Code tacoma command_line
Code tacoma command_lineCode tacoma command_line
Code tacoma command_lineAndrea Urban
 
Productivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformaticsProductivity tips - Introduction to linux for bioinformatics
Productivity tips - Introduction to linux for bioinformaticsBITS
 
Unix Commands
Unix CommandsUnix Commands
Unix CommandsDr.Ravi
 
Text mining on the command line - Introduction to linux for bioinformatics
Text mining on the command line - Introduction to linux for bioinformaticsText mining on the command line - Introduction to linux for bioinformatics
Text mining on the command line - Introduction to linux for bioinformaticsBITS
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
 
Part 6 of "Introduction to linux for bioinformatics": Productivity tips
Part 6 of "Introduction to linux for bioinformatics": Productivity tipsPart 6 of "Introduction to linux for bioinformatics": Productivity tips
Part 6 of "Introduction to linux for bioinformatics": Productivity tipsJoachim Jacob
 

More Related Content

What's hot

Unix Basics 04sp
Unix Basics 04spUnix Basics 04sp
Unix Basics 04spDr.Ravi
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
Basic linux commands for bioinformatics
Basic linux commands for bioinformaticsBasic linux commands for bioinformatics
Basic linux commands for bioinformaticsBonnie Ng
 
(Practical) linux 104
(Practical) linux 104(Practical) linux 104
(Practical) linux 104Arie Bregman
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filtersbhatvijetha
 
The structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsThe structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsBITS
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processingAnton Arhipov
 
UNIX Command Cheat Sheets
UNIX Command Cheat SheetsUNIX Command Cheat Sheets
UNIX Command Cheat SheetsPrashanth Kumar
 
Managing your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformaticsManaging your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformaticsBITS
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examplesabclearnn
 
Ansible for Beginners
Ansible for BeginnersAnsible for Beginners
Ansible for BeginnersArie Bregman
 

What's hot (20)

Unix Basics 04sp
Unix Basics 04spUnix Basics 04sp
Unix Basics 04sp
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
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
 
Linux basics
Linux basicsLinux basics
Linux basics
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Basic linux commands for bioinformatics
Basic linux commands for bioinformaticsBasic linux commands for bioinformatics
Basic linux commands for bioinformatics
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Linux networking
Linux networkingLinux networking
Linux networking
 
(Practical) linux 104
(Practical) linux 104(Practical) linux 104
(Practical) linux 104
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
 
Piping into-php
Piping into-phpPiping into-php
Piping into-php
 
The structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformaticsThe structure of Linux - Introduction to Linux for bioinformatics
The structure of Linux - Introduction to Linux for bioinformatics
 
Linux
LinuxLinux
Linux
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processing
 
UNIX Command Cheat Sheets
UNIX Command Cheat SheetsUNIX Command Cheat Sheets
UNIX Command Cheat Sheets
 
Managing your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformaticsManaging your data - Introduction to Linux for bioinformatics
Managing your data - Introduction to Linux for bioinformatics
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
Ansible for Beginners
Ansible for BeginnersAnsible for Beginners
Ansible for Beginners
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 

Viewers also liked

Administracion )
Administracion )Administracion )
Administracion )jackebt
 
Tracking trollers
Tracking trollersTracking trollers
Tracking trollersLiz Henry
 
Cartilla Part 2
Cartilla Part 2Cartilla Part 2
Cartilla Part 2jackebt
 
S I S T E M A D E I N V E N T A R I O P E R M A N E N T E
S I S T E M A  D E  I N V E N T A R I O  P E R M A N E N T ES I S T E M A  D E  I N V E N T A R I O  P E R M A N E N T E
S I S T E M A D E I N V E N T A R I O P E R M A N E N T Ejackebt
 
Code Of Our Own
Code Of Our OwnCode Of Our Own
Code Of Our OwnLiz Henry
 
Crowdsourced fact checking
Crowdsourced fact checkingCrowdsourced fact checking
Crowdsourced fact checkingLiz Henry
 
Bad inventions-talk
Bad inventions-talkBad inventions-talk
Bad inventions-talkLiz Henry
 
Fight Spam and Hackers!
Fight Spam and Hackers!Fight Spam and Hackers!
Fight Spam and Hackers!Liz Henry
 
Fake lesbians all the way down
Fake lesbians all the way downFake lesbians all the way down
Fake lesbians all the way downLiz Henry
 
Hackability: Free/Open Source Assistive Tech
Hackability: Free/Open Source Assistive TechHackability: Free/Open Source Assistive Tech
Hackability: Free/Open Source Assistive TechLiz Henry
 
Using The Unix Command Line
Using The Unix Command LineUsing The Unix Command Line
Using The Unix Command Lineadil raja
 
Unix Shell Tricks for Rails Developers
Unix Shell Tricks for Rails DevelopersUnix Shell Tricks for Rails Developers
Unix Shell Tricks for Rails DevelopersMatthew Swain
 
Cartilla Part 2
Cartilla Part 2Cartilla Part 2
Cartilla Part 2jackebt
 
The GimpGirl Online Community
The GimpGirl Online CommunityThe GimpGirl Online Community
The GimpGirl Online CommunityLiz Henry
 
Mastering the Unix Command Line
Mastering the Unix Command LineMastering the Unix Command Line
Mastering the Unix Command LineHoward Mao
 

Viewers also liked (20)

Administracion )
Administracion )Administracion )
Administracion )
 
Tracking trollers
Tracking trollersTracking trollers
Tracking trollers
 
Cartilla Part 2
Cartilla Part 2Cartilla Part 2
Cartilla Part 2
 
S I S T E M A D E I N V E N T A R I O P E R M A N E N T E
S I S T E M A  D E  I N V E N T A R I O  P E R M A N E N T ES I S T E M A  D E  I N V E N T A R I O  P E R M A N E N T E
S I S T E M A D E I N V E N T A R I O P E R M A N E N T E
 
Code Of Our Own
Code Of Our OwnCode Of Our Own
Code Of Our Own
 
Crowdsourced fact checking
Crowdsourced fact checkingCrowdsourced fact checking
Crowdsourced fact checking
 
Bad inventions-talk
Bad inventions-talkBad inventions-talk
Bad inventions-talk
 
Fight Spam and Hackers!
Fight Spam and Hackers!Fight Spam and Hackers!
Fight Spam and Hackers!
 
Fake lesbians all the way down
Fake lesbians all the way downFake lesbians all the way down
Fake lesbians all the way down
 
Hackability: Free/Open Source Assistive Tech
Hackability: Free/Open Source Assistive TechHackability: Free/Open Source Assistive Tech
Hackability: Free/Open Source Assistive Tech
 
Using The Unix Command Line
Using The Unix Command LineUsing The Unix Command Line
Using The Unix Command Line
 
Unix Shell Tricks for Rails Developers
Unix Shell Tricks for Rails DevelopersUnix Shell Tricks for Rails Developers
Unix Shell Tricks for Rails Developers
 
Unix command quickref
Unix command quickrefUnix command quickref
Unix command quickref
 
Cut command in unix
Cut command in unixCut command in unix
Cut command in unix
 
Unix
UnixUnix
Unix
 
Cartilla Part 2
Cartilla Part 2Cartilla Part 2
Cartilla Part 2
 
The GimpGirl Online Community
The GimpGirl Online CommunityThe GimpGirl Online Community
The GimpGirl Online Community
 
ReassAmblycaj
ReassAmblycajReassAmblycaj
ReassAmblycaj
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
Mastering the Unix Command Line
Mastering the Unix Command LineMastering the Unix Command Line
Mastering the Unix Command Line
 

Similar to Love Your Command Line

Similar to Love Your Command Line (20)

DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
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
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
2023comp90024_linux.pdf
2023comp90024_linux.pdf2023comp90024_linux.pdf
2023comp90024_linux.pdf
 
Unix
UnixUnix
Unix
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
Directories description
Directories descriptionDirectories description
Directories description
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Python1
Python1Python1
Python1
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
MCLS 45 Lab Manual
MCLS 45 Lab ManualMCLS 45 Lab Manual
MCLS 45 Lab Manual
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Unix commands
Unix commandsUnix commands
Unix commands
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linux command for beginners
Linux command for beginnersLinux command for beginners
Linux command for beginners
 
unix_commands.ppt
unix_commands.pptunix_commands.ppt
unix_commands.ppt
 

Recently uploaded

2024 February Patch Tuesday
2024 February Patch Tuesday2024 February Patch Tuesday
2024 February Patch TuesdayIvanti
 
Curtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfCurtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfDomotica daVinci
 
Bringing nullability into existing code - dammit is not the answer.pptx
Bringing nullability into existing code - dammit is not the answer.pptxBringing nullability into existing code - dammit is not the answer.pptx
Bringing nullability into existing code - dammit is not the answer.pptxMaarten Balliauw
 
CIRCLE geometry lesson 2nd quarter grade 10
CIRCLE geometry lesson 2nd quarter  grade 10CIRCLE geometry lesson 2nd quarter  grade 10
CIRCLE geometry lesson 2nd quarter grade 10RicFernandez4
 
Breaking Barriers & Leveraging the Latest Developments in AI Technology
Breaking Barriers & Leveraging the Latest Developments in AI TechnologyBreaking Barriers & Leveraging the Latest Developments in AI Technology
Breaking Barriers & Leveraging the Latest Developments in AI TechnologySafe Software
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasScyllaDB
 
Navigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersNavigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersOnePlan Solutions
 
M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____Aathiraju
 
AUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMING
AUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMINGAUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMING
AUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMINGLiveplex
 
AWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user groupAWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user groupAWS Chicago
 
My self introduction to know others abut me
My self  introduction to know others abut meMy self  introduction to know others abut me
My self introduction to know others abut meManoj Prabakar B
 
Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Daniel Toomey
 
Tete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdfTete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdfDomotica daVinci
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manualDomotica daVinci
 
Z-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdf
Z-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdfZ-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdf
Z-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdfDomotica daVinci
 
Q1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product LineupQ1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product LineupMemory Fabric Forum
 
Artificial-Intelligence-in-Marketing-Data.pdf
Artificial-Intelligence-in-Marketing-Data.pdfArtificial-Intelligence-in-Marketing-Data.pdf
Artificial-Intelligence-in-Marketing-Data.pdfIsidro Navarro
 
2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx
2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx
2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptxssuser796efb
 
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?GleecusTechlabs1
 

Recently uploaded (20)

2024 February Patch Tuesday
2024 February Patch Tuesday2024 February Patch Tuesday
2024 February Patch Tuesday
 
Curtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfCurtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdf
 
Bringing nullability into existing code - dammit is not the answer.pptx
Bringing nullability into existing code - dammit is not the answer.pptxBringing nullability into existing code - dammit is not the answer.pptx
Bringing nullability into existing code - dammit is not the answer.pptx
 
CIRCLE geometry lesson 2nd quarter grade 10
CIRCLE geometry lesson 2nd quarter  grade 10CIRCLE geometry lesson 2nd quarter  grade 10
CIRCLE geometry lesson 2nd quarter grade 10
 
Breaking Barriers & Leveraging the Latest Developments in AI Technology
Breaking Barriers & Leveraging the Latest Developments in AI TechnologyBreaking Barriers & Leveraging the Latest Developments in AI Technology
Breaking Barriers & Leveraging the Latest Developments in AI Technology
 
Dissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance DilemmasDissecting Real-World Database Performance Dilemmas
Dissecting Real-World Database Performance Dilemmas
 
Navigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersNavigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio Leaders
 
M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____
 
AUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMING
AUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMINGAUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMING
AUGMENTED REALITY (AR) IN DAILY LIFE: EXPANDING BEYOND GAMING
 
AWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user groupAWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user group
 
My self introduction to know others abut me
My self  introduction to know others abut meMy self  introduction to know others abut me
My self introduction to know others abut me
 
My Country Mobile
My Country MobileMy Country Mobile
My Country Mobile
 
Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024
 
Tete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdfTete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdf
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
 
Z-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdf
Z-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdfZ-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdf
Z-Wave Fan coil Thermostat Heltun_HE-HT01_User_Manual.pdf
 
Q1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product LineupQ1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product Lineup
 
Artificial-Intelligence-in-Marketing-Data.pdf
Artificial-Intelligence-in-Marketing-Data.pdfArtificial-Intelligence-in-Marketing-Data.pdf
Artificial-Intelligence-in-Marketing-Data.pdf
 
2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx
2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx
2) Presentation_Overview_ISO_16140-3_Method_verification_20210322.pptx
 
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
Unlocking the Cloud's True Potential: Why Multitenancy Is The Key?
 

Love Your Command Line

  • 1. Stupid Unix Tricks or Love Your Command Line! Liz Henry BlogHer 2009
  • 2. The command line is like your trusty robot friend always waiting for you to tell it what to do! How do I get to the command line? MacOS or Linux: Terminal Windows: HyperTerminal or PuTTY, CygWin You can get these slides from my blog or we'll download them at end of session, so don't worry about taking notes!
  • 3. Navigation: Where are you? pwd Print(current) working directory ls “list” files in the directory you're in. Type this a lot! cd change directory (blank will take you to your home dir) mkdir dev Make a directory called “dev” in your current working directory cd dev change into that directory! whee! ls What's in there? Probably nothing since you just made it. pwd where are you again? up arrow key Push it a few times. It shows the commands you last typed.
  • 4. Navigation: Where are you? echo $SHELL What command line shell am I in? tcsh, csh, bash? whoami So existential! What's my username? hostname What's the name of the computer or server I'm on? ping google.com Are you on the net? (Control-C to stop this) ifconfig Really, how about that network!? Cryptic... traceroute google.com Where am I really? In relation to somewhere else? easy challenge: Poke around and see what other environment variables you can echo! Hint, type “printenv” harder challenge: change your prompt to be in color and tell you what directory you're in (look up later and try it)
  • 5. Look around some more! man ps alias woman=”man” alias wom=”man” wom ls Q to quit reading man pages alias ls = “ls -lah” ps ps -x Whoa! ps -x | more Pipes the output into a paging program Q to quit ps -x | grep Term Pipe into “grep” to search for specific process top Info about top processes (Q to quit)
  • 6. Get remote files First use curl or wget to download two sample text files. curl -O http://bookmaniac.org/stuff/slides/example.tar.zip or wget http://bookmaniac.org/stuff/slides/example.tar.zip ls There's the file, tarred and zipped up tar -xvzf example.tar.zip Uncompress the files! ls Reassure yourself... cat bloglist.txt Take a look at the file contents cat stats.txt ls -lahFSr Fancy! sorts by file size. Challenge for later: Download Wordpress and unzip it from the command line Download some WP themes and unzip them! Challenge: Download and install wget if you don't have it. Then, try downloading an entire web site with its files and images 2 levels deep: wget --wait=9 --recursive --level=2 http://example.org/
  • 7. Manipulate text files sort bloglist.txt This sorts on the first field, alphabetically sort stats.txt sort stats.txt > tmp.txt Sorts into a new file called tmp.txt sort stats.txt | uniq > tmp.txt Sorts, then pipes output to uniq, then writes to a file sort -t',' -k 2,2 stats.txt Sorts with comma as field separator, on field 2 sort -t',' -k 2,2 -nrg stats.txt -nrg means general numerical sort, reverse order There are many more tricks and oneliners, try out all the options for sort, and search for “sort examples unix” or “sort examples command line”
  • 8. Manipulate text files Manipulate text files – Awk is weird but fun awk '{print $1}' bloglist.txt Prints first field, field separator is a blank space awk -F"," '{print $1}' stats.txt Print first field with a comma as field separator awk -F"," '{print $2 $1}' stats.txt Print both fields, the other way round awk -F"," '{print $2 "," $1}' stats.txt Do that again but with a comma separator awk -F"," '{print $2 "," $1}' stats.txt | sort -nr Pipe it through sort, numerical, reversed! awk -F"," '{print $2 "," $1}' stats.txt | sort -nr | mail -s 'Stats from me' lizhenry@gmail.com Email me the results! (“Stats from me” is the subject line)
  • 9. Manipulate text files Manipulate text files – grep and regular expressions Even grep baby talk is incredibly useful! Regular expressions are fantastic. * is a wildcard. It means “match anything” grep Sarah bloglist.txt Shows any lines where “Sarah” appears in that file grep Sarah *.txt Shows any lines containing “Sarah” in any file in this directory grep "S" *.txt Lines containing a capital S grep -r sidebar *.php Look in this directory, and all the ones below it, for any php files that contain the pattern “sidebar” grep -v widget *.css Look in all the css files in this directory for the word “widget” grep -r sidebar *.php | grep -v test As above, but then send the output into another grep filter that will return every line that doesn't match the pattern “test”
  • 10. Manipulate text files – comm, sort, and join comm bloglist.txt stats.txt Compare 2 files. Output is in 3 columns Col 1: lines unique to file 1 Col 2: lines uniq to file 2 Col 3: lines that appear in both files head -1 stats.txt >> bloglist.txt Stick the 1 st line from stats at the end of bloglist. comm bloglist.txt stats.txt Now there is a line in the 3 rd column! comm -12 bloglist.txt stats.txt Suppress column 1 and column 2. sort -t"," -k2,2 bloglist.txt > blogs-sorted.txt Sort on url sort stats.txt > sorted-stats.txt Sort this file on url too
  • 11. Manipulate text files – Apache logs if on blogherista server acct, cd cd examples ls more access.log A sample bit of an Apache log file. awk '{print $1}' access.log | sort | uniq -c | sort -nr pull out the IP numbers of people accessing the site sort them and unique them, counting (-c) the times they appear and sort again numerically, reversed, to see who visits your site most often Try this with the other fields too. What files are accessed most often? What's the most commonly used browser? nslookup 195.240.190.227 Spy on whoever it is a little. whois 195.240.190.227 Some ISP in the Netherlands is downloading my music. Challenge: Go through every example on the fabulous “Awk one-liners” page! http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt
  • 12. Other Useful Stuff to Try scp filename.txt [email_address] :path/to/files/ Copy some files from where you are to a remote account. tar -cvzf target-filename.tar.gz file1.txt file2.txt *.html *.jpg Compress and zip some files. ftp -i [email_address] Handy. -i means you don't have to type y y y at every file it's uploading. make a bunch of aliases in your .bash_profile or other shell profile. Understand the drwxrwxrwx stuff from the ls -a command. And learn to use chmod. Try a lot of grep examples. Do the Bash for Beginners tutorial. Have fun!