Script to find out particular file type in UNIX

In day to day system administration tasks, In some situations, you may need to find out a particular file type (ex: script files, regular files, etc..)  in large file systems. I had a situation to find out only script files (Shell and Perl Scripts) which are using "rsh" in the script code in a very large file system which contains more than 1,00,000 files.

I wrote a simple script to achieve this task. I am sharing this here, because this may be helpful to others as well.This script can be altered little to find out other file types as well.

find /GIS -type f | while read filename
 filetype=$(file $filename | awk -F: '{print $2}'| awk '{print $2}')
 if [ "$filetype" == "script" ];then
    grep -i rsh $filename > /dev/null
    if [ $? -eq 0 ];then
       echo "$filename" >> /tmp/rsh_scripts_report

Share this

Related Posts

Next Post »

What do you think about this Article? Add your Opinion..! EmoticonEmoticon