Skip to content

Instantly share code, notes, and snippets.

@mplscorwin
Created November 11, 2013 22:05
Show Gist options
  • Save mplscorwin/7421299 to your computer and use it in GitHub Desktop.
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
#!/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