Skip to content

Instantly share code, notes, and snippets.

@liggitt
Last active November 12, 2015 18:30
Show Gist options
  • Save liggitt/78423251cfbe6b1aca97 to your computer and use it in GitHub Desktop.
Save liggitt/78423251cfbe6b1aca97 to your computer and use it in GitHub Desktop.
#!/bin/bash
mkdir -p 0-rwx-/1000-rwx-/2000-rwx-/0-rw-/1000-rw-/2000-rw-/0-r-/1000-r-/2000-r-/0--/1000--/2000--/x
mkdir -p 0--rwx/1000--rwx/2000--rwx/0--rw/1000--rw/2000--rw/0--r/1000--r/2000--r/0--/1000--/2000--/x
# create a file in each dir
find . -type d | xargs -n 1 bash -c 'touch "$@"/myfile' {}
# owned by some user/group
find . -name myfile | xargs chown 3000
find . -name myfile | xargs chgrp 3000
# with no permissions at all
find . -name myfile | xargs chmod a=
# change owner
find . -name "0-*" | xargs chown 0
find . -name "1000-*" | xargs chown 1000
find . -name "2000-*" | xargs chown 2000
# change group
find . -name "0-*" | xargs chgrp 0
find . -name "1000-*" | xargs chgrp 1000
find . -name "2000-*" | xargs chgrp 2000
# change user permissions
find . -name "*--*" | xargs chmod u=
find . -name "*-r-*" | xargs chmod u=r
find . -name "*-rw-*" | xargs chmod u=rw
find . -name "*-rwx-*" | xargs chmod u=rwx
# change group permissions
find . -name "*-" | xargs chmod g=
find . -name "*-r" | xargs chmod g=r
find . -name "*-rw" | xargs chmod g=rw
find . -name "*-rwx" | xargs chmod g=rwx
# remove all other permissions
chmod -R o= .
@liggitt
Copy link
Author

liggitt commented Nov 12, 2015

@deads2k, it does:

$ find . -type d | xargs -n 1 bash -c 'touch "$@"/myfile'
touch: cannot touch ‘/myfile’: Permission denied
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment