31
Hi, my name is Topher I’m a WordPress developer from Grand Rapids MI @topher1kenobe Command Line Awesome Topher DeRosia @topher1kenobe

Command Line Awesome, WordCamp Grand Rapids 2014

Embed Size (px)

DESCRIPTION

Tips for working on the Unix command line

Citation preview

Page 1: Command Line Awesome, WordCamp Grand Rapids 2014

Hi, my name is TopherI’m a WordPress developer

from Grand Rapids MI

@topher1kenobe

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 2: Command Line Awesome, WordCamp Grand Rapids 2014

Command Line

AWESOME

Command Line AwesomeTopher DeRosia

@topher1kenobe

Learning the command line.

Page 3: Command Line Awesome, WordCamp Grand Rapids 2014

1. Concepts2. Basic commands3. Available Programs4. A little fun

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 4: Command Line Awesome, WordCamp Grand Rapids 2014

The Shell

When you open the terminal, you’re in a shell. Bash is the most common shell.

Others are Bourne, csh, zsh, kshCommand Line Awesome

Topher DeRosia@topher1kenobe

Page 5: Command Line Awesome, WordCamp Grand Rapids 2014

Your History

Every command you type is saved in a file called .bash_history

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 6: Command Line Awesome, WordCamp Grand Rapids 2014

Your History

Arrow up to see past commands. Ctrl-r and start typing to search your history.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 7: Command Line Awesome, WordCamp Grand Rapids 2014

Moving Around

Ctrl-a takes you to the beginning of the line. Ctrl-e to the end.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 8: Command Line Awesome, WordCamp Grand Rapids 2014

Other Keybindings

Bash uses the same keybindings as the emacs editor.

http://wttools.sourceforge.net/emacs-stuff/emacs-keybindings.html

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 9: Command Line Awesome, WordCamp Grand Rapids 2014

Documentation

“man” pages contain docs for commands. Ex: man cd

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 10: Command Line Awesome, WordCamp Grand Rapids 2014

Flags

Most commands accept modifiers called ‘flags’ like this:

ls -al

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 11: Command Line Awesome, WordCamp Grand Rapids 2014

Change Directories

cdcd path/cd ~/path/cd -Check out the man page.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 12: Command Line Awesome, WordCamp Grand Rapids 2014

Where am I?

pwd == Present Working Directory

Man oh man.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 13: Command Line Awesome, WordCamp Grand Rapids 2014

Make Directories

mkdir mycooldir

Check out the man page, -p is cool.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 14: Command Line Awesome, WordCamp Grand Rapids 2014

List Files

lsls -alls -latr

LOTS of good stuff in the man page.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 15: Command Line Awesome, WordCamp Grand Rapids 2014

Change Files

mv oldfile newfilecp (-R) oldfile newfilerm (-R) file-or-dir

Have I mentioned man pages?

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 16: Command Line Awesome, WordCamp Grand Rapids 2014

Examine Files

morelesscat

man man man man man...

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 17: Command Line Awesome, WordCamp Grand Rapids 2014

Edit Filesnano

VIMemacsjoe

Google knows Al ( ⅔ of All )

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 18: Command Line Awesome, WordCamp Grand Rapids 2014

Search Files

grep (-ir) keyword *ack keyword --php

/ lets you search inside man pages

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 19: Command Line Awesome, WordCamp Grand Rapids 2014

SSH

Encrypted connection to a remote shell

ssh [email protected] (-r) files [email protected]:~/path/

Oh look, there’s a man page.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 20: Command Line Awesome, WordCamp Grand Rapids 2014

wget

Makes one http call and returns the result

wget http://derosia.com/parchment.jpg

Man, I wish there were docs.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 21: Command Line Awesome, WordCamp Grand Rapids 2014

Network Programs

whoishosttracerouteping

Nothing clever, read the man pages.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 22: Command Line Awesome, WordCamp Grand Rapids 2014

Heads and TailsTail shows the last 10 lines of a file.

Head shows the first 10 lines of a file.

Guess how to change the number. (man)

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 23: Command Line Awesome, WordCamp Grand Rapids 2014

Tail -f

-f updates the results as the file changes.

Use this to watch log files.

Ctrl-c quits.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 24: Command Line Awesome, WordCamp Grand Rapids 2014

top

Shows processes, resource use, etc.

Homework: read about ‘load average’

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 25: Command Line Awesome, WordCamp Grand Rapids 2014

mysqlmysql -u username -p database

Puts you on a mysql command line, lets you run SQL queries.

$ man mysqlNo manual entry for mysql

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 26: Command Line Awesome, WordCamp Grand Rapids 2014

Fun stuffcal - shows a calendardate - Shows… the datebc - basic calculator (basic)sl - like ls, but… not

Man, the places you’ll go

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 27: Command Line Awesome, WordCamp Grand Rapids 2014

Voodooperl -pi -e ‘s#search#replace#g’ *

mysql -u user -p database < db_export.sql

tail -f ~/logs/error_log | grep -i exe

cat file | wc -l(counts lines)

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 28: Command Line Awesome, WordCamp Grand Rapids 2014

Homeworkchmodchownlocatekill

Google is your friend here.

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 29: Command Line Awesome, WordCamp Grand Rapids 2014

WP CLIhttp://wp-cli.org/

Interact with the WP admin UI from the command line

wp --help

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 30: Command Line Awesome, WordCamp Grand Rapids 2014

Resourceshttp://www.commandlinefu.com

http://www.commandlinefu.com/commands/by/topher1kenobe

http://cli.learncodethehardway.org/bash_cheat_sheet.pdf

Command Line AwesomeTopher DeRosia

@topher1kenobe

Page 31: Command Line Awesome, WordCamp Grand Rapids 2014

THANKS FOR

LISTENING

Command Line AwesomeTopher DeRosia

@topher1kenobe

http://derosia.com/Follow me @topher1kenobe