Intro to the command line

24
The Command Line Your next best friend that you kinda still hate

description

Presented to attendees of RailsGirls Sydney Nov 2013. The command line. Developers' attitudes and common usage. How to improve your experience with it, from a beginner's perspective.

Transcript of Intro to the command line

Page 1: Intro to the command line

The Command LineYour next best friend that you kinda still hate

Page 2: Intro to the command line

What is it?

• Windows: cmd.exe C:\Users\myusername>

• OSX/Linux: Terminal computername:~ username $

Page 3: Intro to the command line

What is it?

Page 4: Intro to the command line

What do programmers use it for?

In order of most frequent to least frequent:

git statusgit grepgit diffgit addgit loggit checkoutgit commitgit pushgit pullgit showgit rebase

Page 5: Intro to the command line

What else?

rails new myapprails g model Blog title:stringrails consolerails db

Page 6: Intro to the command line

What else?

rake routesrake db:setuprake db:migrate

Page 7: Intro to the command line

Much Less Frequently

brew install rename # Macgem install railsgem list -dgem list -rbundlervm use 1.9rvm use 2.0

Page 8: Intro to the command line

Why should I care?

One year from now you can automate your whole job...

git log $(git merge-base master branch)..branch

cut -f1,2 -d’ ’ ~/.bash_history | sort | uniq -c | sort -nr | head -n 30

wget -mk http://www.stuff.to/read/on/the/train/

rsync -rvP myproject/ username@myhost/myproject.com/

pg_dump --clean -Z 9 app_master | ssh user@apphost ‘zcat | psql -h localhost -U app appdb’

Page 9: Intro to the command line

Don’t Panic

Page 10: Intro to the command line

Basics

cd projects/railsgirls/ # change into a directorycd .. # get out of a directorypwd # print current directory ls -l # list the files here

!

• Pay attention to the “current directory”

• Press the up and down arrows to run previous commands

• Press tab to complete filenames

Page 11: Intro to the command line

Get Unstuck

man wget (spacebar for next page, q to quit)

rails --help

Most reliable: Google “wget command”

Page 12: Intro to the command line

Stay FocusedAs a Rails developer, there are only a handful of commands you’ll use regularly.

gitrspecrakerailsgembundleirbrubysubl / vimopensudossh

Page 13: Intro to the command line

Next Steps

Incrementally improve yourcommand line capability

Page 14: Intro to the command line

git config --global color.ui true

Page 15: Intro to the command line

echo "alias ls='ls -ohG'" >> ~/.bash_profile

Page 16: Intro to the command line

Shortcuts

up, down, tab

up, down, tab

up, down, tab

up, down, tab

up, down, tab

Page 17: Intro to the command line

Ctrl-A start of the lineCtrl-E end of the lineAlt-Delete delete previous wordWorks virtually anywhere! * **

* Terminal, Chrome, Sublime, Evernote, Keynote, XCode, LibreOffice, System Preferences, Gnome, KDE, XFCE4…

** Windows? Not sure.

Page 18: Intro to the command line

More Shortcuts

Ctrl-C stop current command (e.g. rails server)Ctrl-R search for a previous commandAlt-B go back one wordAlt-F go forwards one wordAlt-D delete next word

Page 19: Intro to the command line

Ctrl-R

1. Ctrl-R

2. Start typing (e.g. type “rebas”)

3. Ctrl-R to jump to next oldest match

4. Ctrl-S to jump to next newest match

5. Return to run, Esc to cancel

Page 20: Intro to the command line

Configure Terminal

Page 21: Intro to the command line

Configure iTerm2

Page 22: Intro to the command line

Text

Page 23: Intro to the command line

There Must Be a Better Way!

There usually is

Page 24: Intro to the command line

@gregmcintyre microcourses.info