Sharing Knowledge | System Admin Articles

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

Labels: Automation, scripts, UNIX

My Profile PhotoAbout the Author

I'm Parthiban, An UNIX System Admin by Profession. I'm Experienced in Linux/Unix System Administration and Scripting. I have done lot of work on the infrastructure Mgmt side in Linux, UNIX and Windows system administration, Hardware, Storage and Data center. I'm blogging since 2008.
Follow Me On Twitter or On Facebook

0 Comments for "Script to find out particular file type in UNIX"

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

Back To Top