Mastering the UNIX Command LineHoward Mao March 28, 2013... More About PermissionsI Three types of permissions: read r, write w, execute x I Three categories: user u, group g, other o I
Trang 1Mastering the UNIX Command Line
Howard Mao
March 28, 2013
Trang 2I Created by Ken Thompson and Dennis Ritchie in 1970
I Modern descendants include Linux, OSX, and BSD
Trang 3Looking up Information
I Man Pages: man <command>
I Google is your friend
I Stackexchange Sites
I stackoverflow.com
I serverfault.com
I superuser.com
I unix.stackexchange.com
Trang 4Basic Filesystem Navigation
I look around - ls
I move about - cd, pushd, popd
I move, copy, delete - mv, cp, rm
I file info - stat, du, file
I changing permissions - chmod, chown
Trang 5More 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 each category
I Ex 644 means read + write for user, read only for group and other, execute for nobody
I Execute permission for directory means you can list files in directory
Trang 6I Match everything *
I Choices {foo,bar,baz}
I Characters [abc]
I Numbers {0 5}
Trang 7The Almighty Find
Find allows you to search for files
I By Name: find -name \*.txt
I By Type: find -type d
I By Timestamp: find -mtime 1
I And many many more
Can also run commands on files find -name txt -exec rm {} \;
Trang 8I/O Redirection
I I/O Commands: echo, cat, less
I Input from File: command < input.txt
I Output to File: command > output.txt
I Pipes : command1 | command2
Trang 9I Search lines with grep
I Find and Replace with sed
I Select columns with cut and awk
Trang 10Manipulating Processes
I Start in background: command &
I One after another: command1; command2
I If successful, then: command1 && command2
I If unsuccessful, then: command1 || command2
I Suspend and resume: command <Ctrl>+Z; [bg|fg]
I See running procs: ps, ps -au $USER, ps aux
Trang 11I Server info - ping, traceroute, host, whois
I Sending raw traffic - nc, telnet
I The World Wide Web - wget, curl
I What’s my address? - ip addr, ip link
I What ports are open - ss, nmap
I Who’s on the port - lsof
Trang 12I Believe it or not, the shell is turing complete
I Variables : VAR=abc
I If statements : if [ "$VAR" ]; then echo $VAR; fi
I For loops : for i in {1 5}; do echo $i; done
I While loops : while true; do echo "forever"; done
I User input : read var; echo $var
I Functions : function func () { do something }