Operating System - HP-UX
1752822 Members
4337 Online
108789 Solutions
New Discussion юеВ

check files for embedded code.

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

check files for embedded code.

Im trying to find a way to check a folder that contains 100 directories and 170,000 files, approx, it changes alot.

I want to cat the file and grep for the word "include" and then list the file so I can see the permissions.
Is the best way to do a ls -1 at the root folder, cat every file and grep for 'include' ?
Then Im lost on how to display the file permissions of that file if it finds the word 'include'. stuck...
UNIX IS GOOD
3 REPLIES 3
Patrick Wallek
Honored Contributor
Solution

Re: check files for embedded code.

Something like this should work:

cd /somedir
find . -type f >> filelist

for FILE in $(< filelist)
do
grep -iq include ${FILE} && ls -l ${FILE}
done


The above will create your list of files, then the 'for' loop will loop through those files one at a time, look for 'include' in the file and if it finds it, do an 'ls -l' on the file.
James R. Ferguson
Acclaimed Contributor

Re: check files for embedded code.

Hi:

Patrick's solution is an excellent one. I would change:

# find . -type f >> filelist

...to:

# find . -type f > filelist

...however, so that multiple invocations of the script don't mix new results into old ones.

Remember that if you have multiple directories to search you can stack them like:

# find /home /usr/local . -type f -print

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: check files for embedded code.

>Patrick: for FILE in $(< filelist)

Hmm, it appears this scheme isn't limited to ARG_MAX bytes, about 2 Mb. I've just done 65 Mb.

If you have more files than this, you'll need to use xargs or while:
find . -type f | while read FILE; do
grep -iq include ${FILE} && ls -l ${FILE}
done

Also if you don't want to find "included", you can add "-w" to the grep.