Skip to content

Instantly share code, notes, and snippets.

@kaosf
Last active July 31, 2022 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaosf/596d6b7f010340a36e70eacb454c5e49 to your computer and use it in GitHub Desktop.
Save kaosf/596d6b7f010340a36e70eacb454c5e49 to your computer and use it in GitHub Desktop.
File/Directory permissions resetter
# All file permissions are changed:
# 7xx -> 750
# 6xx -> 640
# All directory permissions are changed:
# 7xx -> 750
# `ls -l` output's 4th byte is owner's execute permission "x" or "-"
chmod -R o-rwx .
chmod -R g-w .
chmod -R g+r .
find . -type d | xargs -i chmod g+rx {}
cat <<'EOF' > /tmp/cmd
#!/bin/bash
FILEPATH=$1
if [ $(ls -l "$FILEPATH" | cut -b 4) == x ]; then
echo chmod g+x "$FILEPATH"
chmod g+x "$FILEPATH"
else
echo chmod g-x "$FILEPATH"
chmod g-x "$FILEPATH"
fi
EOF
chmod +x /tmp/cmd
find . -type f | xargs -i /tmp/cmd {}
rm /tmp/cmd
@kaosf
Copy link
Author

kaosf commented Jul 31, 2022

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