Upgrade to Pro — share decks privately, control downloads, hide ads and more …

chown, chmod, umask, xargs, apropos, python -m

chown, chmod, umask, xargs, apropos, python -m

yeukhon

May 02, 2014
Tweet

More Decks by yeukhon

Other Decks in Programming

Transcript

  1. Unix-like File Permissions 100 010 001 4 2 1 read

    r write w execute x {0,1} {0..9}
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. ch own changes file owner and group change mode chown

    [options] [OWNER/id]:[GROUP/id] FILE [<space> 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
  9. 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.
  10. 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
  11. 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
  12. 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)
  13. 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
  14. x args build and execute command lines from std input

    execute std-input <command>+ | 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"
  15. apropos search manual page names and descriptions apropos <keyword> [{space}

    keyword]* apropos zip …. gunzip (1) - compress or expand files gzip (1) - compress or expand files
  16. python -m timeit python -m timeit -n 100 -r 5

    "[x for x in xrange(0,1000)]"
  17. More python -m? I am not sure. I found trace

    by doing find . "*.py$" | xargs grep "__main__" | less timeit, json.tool are in documentation