Last active
July 31, 2022 13:34
-
-
Save kaosf/596d6b7f010340a36e70eacb454c5e49 to your computer and use it in GitHub Desktop.
File/Directory permissions resetter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trackback: https://twitter.com/ka_/status/1553718151082229762