Slide 1

Slide 1 text

which * chown * chmod * umask * xargs * apropos * python -m

Slide 2

Slide 2 text

File Permissions

Slide 3

Slide 3 text

Unix-like File Permissions 100 010 001 4 2 1 read r write w execute x {0,1} {0..9}

Slide 4

Slide 4 text

Unix-like File Permissions r -> read w -> write x -> execute r w x r w x r w x owner u group g other o 7 7 7

Slide 5

Slide 5 text

Unix-like File Permissions ● Default values: file has 644 (rw,rw,r) dir has 775 (rwx, rwx, r-x) or is it ● Inside a directory, read is for listing files write is for writing to files (and metadata) execute is for entering the directory

Slide 6

Slide 6 text

chmod

Slide 7

Slide 7 text

ch mod changes permission mode on files change mode chmod [options] modes[,modes]* FILE[,FILE]* chmod 644 foo.txt => give foo.txt 644 permission chmod u+x foo.sh => give owner exec permission on foo.sh chmod a+x foo.sh => give EVERYONE exec permission on foo.sh chmod o-x foo.sh => drop exec permission on foo.sh for OTHER chmod u=x foo.sh => apply exec permission to owner BUT drop other unmentioned bits from owner. Result is --x. chmod -R 644 dir1 => give 644 permission recursively to dir1

Slide 8

Slide 8 text

ch mod Give foo.sh permission 755 (attempt 1). change mode foo.sh rw- rw- r-- chmod 755 foo.sh foo.sh rw r-x r-x

Slide 9

Slide 9 text

ch mod Give foo.sh permission 755 (attempt 2). change mode foo.sh rw- rw- r-- chmod g+x foo.sh foo.sh rw- rwx r-- chmod g-w foo.sh foo.sh rw- r-x r-- chmod o=x foo.sh foo.sh rw- r-x --x chmod o+r foo.sh foo.sh rw- r-x r-x chmod u+x foo.sh foo.sh rwx r-x r-x

Slide 10

Slide 10 text

ch mod Give foo.sh permission 755 (attempt 3). change mode before foo.sh rw- rw- r-- chmod go+x,g-w foo.sh now foo.sh rw- r-x r-x

Slide 11

Slide 11 text

chown

Slide 12

Slide 12 text

ch own changes file owner and group change mode chown [options] [OWNER/id]:[GROUP/id] FILE [ FILE]* chmod uFoo file.sh => owner = uFoo chmod uFoo: file.sh => owner = uFoo, group = uFoo’s group (gFoo) chmod :gBar file.sh => owner = unchanged, group = gBar chmod 1001:gBar file.sh => owner = uFoo (uid=1001), group = gBar chmod : file.sh => owner = unchanged, group = unchanged chmod -R uFoo:gBar dir1 => apply owner=uFoo, group=gBar recursievely chmod uFoo:gBar file1.sh file2.py => apply owner and group to file1.sh & file2.py

Slide 13

Slide 13 text

umask

Slide 14

Slide 14 text

Unix-like File Permissions (revisit) ● Default values: file has 644 (rw,rw,r) dir has 775 (rwx, rwx, r-x) I actually kinda misled you about the default values because of umask. In reality, files should have 666 and 777 for dirs.

Slide 15

Slide 15 text

Apply umask to directories r -> read w -> write x -> execute r w x r w x r w x 7 7 7 umask 0 2 2 7 5 5

Slide 16

Slide 16 text

Apply umask to files r -> read w -> write x -> execute r w - r w - r w - 6 6 6 umask 0 2 2 6 4 4

Slide 17

Slide 17 text

u mask set file mode creation mask user file creation mask umask [value] umask => prints the current umask value umask 200 => assign new umask value to 200 (mask out owner’s write permission) umask 077 => assign new umask value to 077 (new file and dir will only be readable and writable by owner)

Slide 18

Slide 18 text

Apply new umask (077) to files r -> read w -> write x -> execute r w - r w - r w - 6 6 6 umask 0 7 7 6 0 0

Slide 19

Slide 19 text

cheat sheet http://bit.ly/1n8AvHH

Slide 20

Slide 20 text

xargs

Slide 21

Slide 21 text

x args build and execute command lines from std input execute std-input + | xargs [options] [args] The most famous usage of xargs is piping find, locate to xargs. 1. Find all file ends with .swp extension and execute rm on each result find . -name “*.swp” | xargs rm 2. Search all files ends with .py and then grep the keywords “import foo” find . -name "*.py" | xargs grep "import foo"

Slide 22

Slide 22 text

apropos

Slide 23

Slide 23 text

apropos search manual page names and descriptions apropos [{space} keyword]* apropos zip …. gunzip (1) - compress or expand files gzip (1) - compress or expand files

Slide 24

Slide 24 text

finally...

Slide 25

Slide 25 text

python -m blah blah

Slide 26

Slide 26 text

python -m SimpleHTTPServer [port]

Slide 27

Slide 27 text

python -m timeit python -m timeit -n 100 -r 5 "[x for x in xrange(0,1000)]"

Slide 28

Slide 28 text

echo '{"b":2, "a":1}' | python -m json. tool { "a": 1, "b": 2 } (validate JSON)

Slide 29

Slide 29 text

python -m trace [options] python -m trace --trace trace.py

Slide 30

Slide 30 text

More python -m? I am not sure. I found trace by doing find . "*.py$" | xargs grep "__main__" | less timeit, json.tool are in documentation