+ All Categories
Home > Technology > Unix shell talk - RIT SSE

Unix shell talk - RIT SSE

Date post: 15-Jan-2015
Category:
Upload: matt-mokary
View: 107 times
Download: 1 times
Share this document with a friend
Description:
Tech Talk given at the Rochester Institute of Technology's Society of Software Engineers about basic unix shell usage and productivity tips.
Popular Tags:
86
Text shells Matt Mokary and important productivity tips
Transcript
Page 1: Unix shell talk - RIT SSE

Text shellsMatt Mokary

and important productivity tips

Page 2: Unix shell talk - RIT SSE

TERMINAL-ogy● Terminal window terminal window

Page 3: Unix shell talk - RIT SSE

TERMINAL-ogy● Terminal window

● Terminal emulatorterminal emulator

terminal window

Page 4: Unix shell talk - RIT SSE

TERMINAL-ogy● Terminal window

● Terminal emulatorterminal emulator

terminal window

Page 5: Unix shell talk - RIT SSE

TERMINAL-ogy● Terminal window

● Terminal emulator

● Shell

terminal emulator

shell

terminal window

Page 6: Unix shell talk - RIT SSE

Modern Shells● C Shell (csh)

● Bourne Again Shell (bash)

● Korn Shell (ksh)

● Z Shell (zsh)

Page 7: Unix shell talk - RIT SSE

Modern Shells● C Shell (csh)

● Bourne Again Shell (bash)

● Korn Shell (ksh)

● Z Shell (zsh)

Page 8: Unix shell talk - RIT SSE

Basic usage<program name> <program flags> [ arg1, arg2, … ]

$ ls

Page 9: Unix shell talk - RIT SSE

Basic usage<program name> <program flags> [ arg1, arg2, … ]

$ ls

Applications Documents Library

Desktop Downloads Music

$

Page 10: Unix shell talk - RIT SSE

Basic usage<program name> <program flags> [ arg1, arg2, … ]

$ ls -a

Page 11: Unix shell talk - RIT SSE

<program name> <program flags> [ arg1, arg2, … ]

$ ls -adrwxr-xr-x 3 mattmokary staff 102 Feb 24 12:56 Applications

drwx------+ 5 mattmokary staff 170 Mar 20 17:06 Desktop

drwx------+ 11 mattmokary staff 374 Mar 20 12:03 Documents

drwx------+ 56 mattmokary staff 1904 Mar 20 14:54 Downloads

drwx------@ 49 mattmokary staff 1666 Feb 12 15:42 Library

drwx------+ 5 mattmokary staff 170 Feb 20 00:12 Music

$

Basic usage

Page 12: Unix shell talk - RIT SSE

<program name> <program flags> [ arg1, arg2, … ]

$ grep -n TODO MyProject.java

Basic usage

Page 13: Unix shell talk - RIT SSE

Basic usage<program name> <program flags> [ arg1, arg2, … ]

$ grep -n TODO MyProject.java

23: // TODO is there an off-by-one error here?

131: // TODO document this function

340: // TODO make this more efficient

$

Page 14: Unix shell talk - RIT SSE

<program name> <program flags> [ arg1, arg2, … ]

$ gcc -o HelloWorld hello_world.c

Basic usage

Page 15: Unix shell talk - RIT SSE

<program name> <program flags> [ arg1, arg2, … ]

$ gcc -o HelloWorld hello_world.c

$

Basic usage

Page 16: Unix shell talk - RIT SSE

<program name> <program flags> [ arg1, arg2, … ]

$ gcc -o HelloWorld hello_world.c

$ ls

HelloWorld hello_world.c hello_world.o

$

Basic usage

Page 17: Unix shell talk - RIT SSE

Streams

Page 18: Unix shell talk - RIT SSE

Streams● Standard Input (stdin)

Page 19: Unix shell talk - RIT SSE

Streams● Standard Input (stdin)

● Standard Output (stdout)

Page 20: Unix shell talk - RIT SSE

Streams● Standard Input (stdin)

● Standard Output (stdout)

● Standard Error (stderr)

Page 21: Unix shell talk - RIT SSE

Streams$ cat test.txt

Page 22: Unix shell talk - RIT SSE

Streams$ cat test.txtThis is a test file.It has several lines,none of which are very helpful.This is the last line of the file.$

Page 23: Unix shell talk - RIT SSE

Stream Redirection● >

Page 24: Unix shell talk - RIT SSE

Stream Redirection● > $ grep TODO MyProject.java

Page 25: Unix shell talk - RIT SSE

Stream Redirection● > $ grep TODO MyProject.java

// TODO make this better

// TODO delete these

$

Page 26: Unix shell talk - RIT SSE

Stream Redirection● > $ grep TODO MyProject.java > todo.txt

Page 27: Unix shell talk - RIT SSE

Stream Redirection● > $ grep TODO MyProject.java > todo.txt

$

Page 28: Unix shell talk - RIT SSE

Stream Redirection● > $ grep TODO MyProject.java > todo.txt

$ ls

MyProject.java todo.txt

$

Page 29: Unix shell talk - RIT SSE

Stream Redirection● > $ grep TODO MyProject.java > todo.txt

$ ls

MyProject.java todo.txt

$ cat todo.txt

// TODO make this better

// TODO delete these

$

Page 30: Unix shell talk - RIT SSE

Stream Redirection● >

>>

$ grep TODO MyProject.java > todo.txt

$ ls

MyProject.java todo.txt

$ cat todo.txt

// TODO make this better

// TODO delete these

$

Page 31: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

Page 32: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

$ grep TODO MyProject.java

// TODO make this better

// TODO delete these

$

Page 33: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

$ grep TODO < MyProject.java

// TODO make this better

// TODO delete these

$

Page 34: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

● |

Page 35: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

● |

$ grep TODO MyProject.java > todo.txt

$ wc -l todo.txt

2

$ rm todo.txt

Page 36: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

● |

$ grep TODO MyProject.java | wc -l

Page 37: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

● |

$ grep TODO MyProject.java | wc -l

2

Page 38: Unix shell talk - RIT SSE

Stream Redirection● >

>>

● <

● |

$ grep TODO MyProject.java | wc -l

2

$ ruby get_hockey_tweets.rb \

| grep -in sedin | grep -i henrik \

| wc -l

173

$

Page 39: Unix shell talk - RIT SSE

Stream Redirection● > redirect stdout to file stream

>> append stdout to file stream

● < redirect file stream to stdin

● | redirect stdout and stderr to stdin

Page 40: Unix shell talk - RIT SSE

Stream Redirection● stdin (channel 0)

● stdout (channel 1)

● stderr (channel 2)

Page 41: Unix shell talk - RIT SSE

Stream Redirection$ ./sqrt -1 2> errors.txt

No real solution.

$

Page 42: Unix shell talk - RIT SSE

Stream Redirection$ ./sqrt -1 2> errors.txt

No real solution.

$ cat errors.txt

Argument is less than zero.

$

Page 43: Unix shell talk - RIT SSE

Stream Redirection$ ./sqrt -1 2> errors.txt 1> /dev/null

$ cat errors.txt

Argument is less than zero.

$

Page 44: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

Page 45: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

Page 46: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

Page 47: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

Page 48: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

Page 49: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

Page 50: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

$

Page 51: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

$ ls

postfix-solver syntax-errors.txt

$

Page 52: Unix shell talk - RIT SSE

Stream Redirection$ ./postfix-solver 3 4 + 2>&1 > /dev/null \

| grep syntax > syntax-errors.txt

$ ls

postfix-solver syntax-errors.txt

$ cat syntax-errors.txt

$

Page 53: Unix shell talk - RIT SSE

Stream Redirection● stdin 0● stdout 1● stderr 2● 2> redirect stderr to file stream● 2>&1 redirect stderr to current stdout

etc.

Page 54: Unix shell talk - RIT SSE

Every SE Ever:

Page 55: Unix shell talk - RIT SSE

Every SE Ever:“I have no idea why this isn’t working.”

Page 56: Unix shell talk - RIT SSE

Every SE Ever:“I have no idea why this isn’t working.”

“I have no idea why this is working.”

Page 57: Unix shell talk - RIT SSE

Every SE Ever:“I have no idea why this isn’t working.”

“I have no idea why this is working.”

“How do I get out of vim?”

Page 58: Unix shell talk - RIT SSE

vim Modes● Normal

Page 59: Unix shell talk - RIT SSE

vim Modes● Normal

o insert a new line beneath the cursor, move to it,and enter insert mode

$ move to the end of the line and remain innormal mode

i enter insert mode at the cursor’s currentposition

I move to the beginning of the line and enterinsert mode

dd cut the current line

Page 60: Unix shell talk - RIT SSE

vim Modes● Normal

● Insert

Page 61: Unix shell talk - RIT SSE

vim Modes● Normal

● Insert

● Command

Page 62: Unix shell talk - RIT SSE

vim Modes● Normal

● Insert

● Command

:w write the buffer to the disk

:q quit vim; will stop you if the file has changedsince the last write

:q! quit vim and discard changes since last write

:wq write the buffer and quit vim

:x same as :wq

:<some number>move the cursor to line <some number>

Page 63: Unix shell talk - RIT SSE

Typical vim Workflow

Page 64: Unix shell talk - RIT SSE

Typical vim Workflow$ vim some-file.txt

Page 65: Unix shell talk - RIT SSE

Typical vim Workflow$ vim some-file.txt

until you’ve made all the desired changes:navigate through the file in normal mode

Page 66: Unix shell talk - RIT SSE

Typical vim Workflow$ vim some-file.txt

until you’ve made all the desired changes:navigate through the file in normal modebounce between normal and insert until part is fixed

Page 67: Unix shell talk - RIT SSE

Typical vim Workflow$ vim some-file.txt

until you’ve made all the desired changes:navigate through the file in normal modebounce between normal and insert until part is fixedenter normal mode and write the file with “:w”

Page 68: Unix shell talk - RIT SSE

Typical vim Workflow$ vim some-file.txt

until you’ve made all the desired changes:navigate through the file in normal modebounce between normal and insert until part is fixedenter normal mode and write the file with “:w”

enter normal mode

Page 69: Unix shell talk - RIT SSE

Typical vim Workflow$ vim some-file.txt

until you’ve made all the desired changes:navigate through the file in normal modebounce between normal and insert until part is fixedenter normal mode and write the file with “:w”

enter normal modewrite the file and quit vim with “:wq” or “:x”

Page 70: Unix shell talk - RIT SSE

vim Visual Mode

Page 71: Unix shell talk - RIT SSE

vim Visual Modex cut the highlighted text and save it to vim’s

clipboard

y copy the highlighted text and save it to vim’sclipboard

p (in normal mode)paste the text in vim’s clipboard into the bufferafter the cursor

P (in normal mode)paste the text in vim’s clipboard into the bufferbefore the cursor

Page 72: Unix shell talk - RIT SSE

tmux

Page 73: Unix shell talk - RIT SSE

tmux$ Shell

Page 74: Unix shell talk - RIT SSE

tmux$ tmux new -s Crypto

$ Shell

tmux session“Crypto”

Page 75: Unix shell talk - RIT SSE

tmux$ tmux new -s Crypto

$ tmux ls

Crypto: 1 windows … (attached)

$

Shell

tmux session“Crypto”

Page 76: Unix shell talk - RIT SSE

tmux$ tmux new -s Crypto

$ tmux ls

Crypto: 1 windows … (attached)

$ tmux detach

$

Shell

tmux session“Crypto”

Page 77: Unix shell talk - RIT SSE

tmux$ tmux new -s Crypto

$ tmux ls

Crypto: 1 windows … (attached)

$ tmux detach

$ tmux new -s Grading

$

Shell

tmux session“Crypto”

tmux session“Grading”

Page 78: Unix shell talk - RIT SSE

tmux$ tmux new -s Crypto

$ tmux ls

Crypto: 1 windows … (attached)

$ tmux detach

$ tmux new -s Grading

$ tmux kill-session -t Crypto

$

Shell

tmux session“Grading”

Page 79: Unix shell talk - RIT SSE

tmux$ tmux new -s Crypto

$ tmux ls

Crypto: 1 windows … (attached)

$ tmux detach

$ tmux new -s Grading

$ tmux kill-session -t Crypto

$ tmux detach

$

Shell

tmux session“Grading”

Page 80: Unix shell talk - RIT SSE

tmux Session

Page 81: Unix shell talk - RIT SSE

tmux SessionCTRL+b % vertical split

Page 82: Unix shell talk - RIT SSE

tmux SessionCTRL+b % vertical split

CTRL+b “ horizontalsplit

Page 83: Unix shell talk - RIT SSE

tmux SessionCTRL+b % vertical split

CTRL+b “ horizontalsplit

CTRL+b x y kill pane

Page 84: Unix shell talk - RIT SSE

tmux SessionCTRL+b % vertical split

CTRL+b “ horizontalsplit

CTRL+b x y kill pane

CTRL+b arrows

navigate panes

Page 85: Unix shell talk - RIT SSE

My Personal Setup

Page 86: Unix shell talk - RIT SSE

Thanks!


Recommended