Find files and fix permissions bash script example

To find files and fix permissions example bash script below can be used:

$ ./find_fix_permissions.sh

#!/bin/bash

CORRECT_PERMISSIONS=644
SEARCH_FOLDER="./images/"

if [ "$(find $SEARCH_FOLDER -type f ! -perm $CORRECT_PERMISSIONS -print)" ]; then
    find $SEARCH_FOLDER -type f ! -perm $CORRECT_PERMISSIONS -print0 |xargs -0 chmod -fv $CORRECT_PERMISSIONS
fi

$

It searches all files in folder SEARCH_FOLDER including sub-folders and if these files found correct permissions set in variable CORRECT_PERMISSIONS

2 thoughts on “Find files and fix permissions bash script example

  1. I cannot thank you enough for the blog article.Really looking forward to read more.
    Really Cool.

Comments are closed.