Unix Shell - Script help needed with file command and such

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2004 > Script help needed with file command and such





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Script help needed with file command and such
James Nykiel

2004-10-08, 8:47 pm

Greetings:


I would like to create a BASH script that is able to drill down through a
directory and its subdirectories, identify all the files that are binary
and perform a chmod on them on the fly.

I think the file command is what I need to use to identify the binary
files, what I am not sure about is how to drill down the directory
structure and supply the listing of each directory to the file command for
for processing.


Thanks - Jim

Muthukumar_K

2004-10-13, 10:43 am

We can simulate binary executable files using find + file command as,


for file in `find / -type f -name "*"`
do

if [[ $(file $file | grep -q 'executable') -eq 0 ]]
then

# File is executable
chmod <mod> $file

fi

done

If you want combine few pattern with executable then add as,

$(file $file | grep -q 'executable' | grep -q 'ELF') -eq 0

there.


HTH.

Regards
Muthukumar
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com