Kevin's Worklog

Documenting the Daily Stream

To Fix the Permissions of a Directory Structure

A fixperms.sh script that will recursively fix the directory permissions to 755 for directories and 644 for files.

#! /bin/bash

if [ $# -eq 0 ] ; then
  DIR=`pwd`
else
  DIR=${1}
fi

if [ ! -e ${1} ]; then
  echo "File or directory \"${1}\" doesn't exist"
  exit 1
fi

find ${DIR} -type d -print0 | xargs -0 chmod 0755
find ${DIR} -type f -print0 | xargs -0 chmod 0644

# Let's treat our bash scripts differently though
for FILE in $(find ${DIR} -name "*.sh"); do
  if [ -e ${FILE} ]; then
    echo "Making ${file} executable"
    chmod -f 0744 ${FILE}
  fi
done