Shell Script - Find list of Files having Write Permission in a directory

In this section, Let us see how to find the Files which are having Write permission enabled in a particular directory.

In the below script, we are going to find the list of all files inside "/cygdrive/c/Shell_Script" which are having Write permission for the user Owner.

The below script will produce a report.csv file which will have writable files list.

FindFilesHavingWritePermission.sh

#
# Script to find the List of Files which are having Write permission enabled in a directory
#

OUTPUT_FILE=report.csv
echo "Name,Status" > ${OUTPUT_FILE}

cd /cygdrive/c/TechDive/Shell_Script

for i in `find . -type f | grep -v ${OUTPUT_FILE}`
{
        fileName=$i
        permission=`ls -ltr ${fileName} | cut -d" " -f1 | cut -b3`

        if [ "${permission}" = 'w' ]
        then
                echo "${fileName} is Writable"
                echo "${fileName}, Writable" >> ${OUTPUT_FILE}
        fi
}

echo "Refer the Report file ie., report.csv"

Script Execution

$ sh FindFilesHavingWritePermission.sh
./1.txt is Writable
./2.txt is Writable
./3.txt is Writable
Refer the Report file ie., report.csv

Report

$ cat report.csv
Name,Status
./1.txt, Writable
./2.txt, Writable
./3.txt, Writable
Technology: 

Search