Created
November 11, 2013 22:05
-
-
Save mplscorwin/7421299 to your computer and use it in GitHub Desktop.
fix the owner/group of all files under a set of directories via find and chown
This file contains 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
#!/bin/bash | |
################################################################################ | |
# | |
# shell script to fix ownership of all files under each entry in SEARCH_PATH | |
# | |
################################################################################ | |
# space seperated list of paths | |
SEARCH_PATHS='/tmp/foo /tmp/bar' | |
# incorrect user for which we are searching | |
SEARCH_USER=root | |
# correct user/group | |
CHOWN_ARGS=cassandra.cassandra | |
### work happens here | |
CHANGE_COUNT=0 | |
for DIR in $SEARCH_PATHS; do | |
CHANGE_COUNT=$(( $CHANGE_COUNT + `find $DIR -user $SEARCH_USER -exec chown $CHOWN_ARGS {} \; -print | wc -l`)) | |
done | |
if [[ $CHANGE_COUNT -gt 0 ]]; then | |
echo [WARNING] ownership of $CHANGE_COUNT files changed from root.\? to $CHOWN_ARGS | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment