mastering the unix command line

12

Click here to load reader

Upload: howard-mao

Post on 24-May-2015

385 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Mastering the Unix Command Line

Mastering the UNIX Command Line

Howard Mao

March 28, 2013

Page 2: Mastering the Unix Command Line

UNIX

I Created by Ken Thompson and Dennis Ritchie in 1970I Modern descendants include Linux, OSX, and BSD

Page 3: Mastering the Unix Command Line

Looking up Information

I Man Pages: man <command>I Google is your friendI Stackexchange Sites

I stackoverflow.comI serverfault.comI superuser.comI unix.stackexchange.com

Page 4: Mastering the Unix Command Line

Basic Filesystem Navigation

I look around - lsI move about - cd, pushd, popdI move, copy, delete - mv, cp, rmI file info - stat, du, fileI changing permissions - chmod, chown

Page 5: Mastering the Unix Command Line

More About Permissions

I Three types of permissions: read (r), write (w), execute (x)I Three categories: user (u), group (g), other (o)I Also represented by an octal number: read (4), write (2),execute (1)

I Add them together to get number. One octal digit for eachcategory

I Ex. 644 means read + write for user, read only for groupand other, execute for nobody

I Execute permission for directory means you can list files indirectory

Page 6: Mastering the Unix Command Line

Globbing

I Match everything *I Choices {foo,bar,baz}I Characters [abc]I Numbers {0..5}

Page 7: Mastering the Unix Command Line

The Almighty Find

Find allows you to search for filesI By Name: find . -name \*.txtI By Type: find . -type dI By Timestamp: find . -mtime 1I And many many more

Can also run commands on filesfind . -name .txt -exec rm {} \;

Page 8: Mastering the Unix Command Line

I/O Redirection

I I/O Commands: echo, cat, lessI Input from File: command < input.txtI Output to File: command > output.txtI Pipes : command1 | command2

Page 9: Mastering the Unix Command Line

Filters

I Search lines with grepI Find and Replace with sedI Select columns with cut and awk

Page 10: Mastering the Unix Command Line

Manipulating Processes

I Start in background: command &I One after another: command1; command2I If successful, then: command1 && command2I If unsuccessful, then: command1 || command2I Suspend and resume: command <Ctrl>+Z; [bg|fg]I See running procs: ps, ps -au $USER, ps aux

Page 11: Mastering the Unix Command Line

Networking

I Server info - ping, traceroute, host, whoisI Sending raw traffic - nc, telnetI The World Wide Web - wget, curlI What’s my address? - ip addr, ip linkI What ports are open - ss, nmapI Who’s on the port - lsof

Page 12: Mastering the Unix Command Line

Scripting

I Believe it or not, the shell is turing completeI Variables : VAR=abcI If statements : if [ "$VAR" ]; then echo $VAR; fiI For loops : for i in {1..5}; do echo $i; doneI While loops : while true; do echo "forever"; doneI User input : read var; echo $varI Functions : function func () { do something }