Operating System - HP-UX
1833792 Members
2242 Online
110063 Solutions
New Discussion

Re: Using the find command to find all executable files.

 
SOLVED
Go to solution
Joanne Keegan
Regular Advisor

Using the find command to find all executable files.

I'm trying to get a listing of all the executable files on our servers. Does anyone know what the command would be to do this? Is the find command the best way to do it?

Your help will be appreciated.

Thanks,

Jo
12 REPLIES 12
Michael Tully
Honored Contributor

Re: Using the find command to find all executable files.

Hi Jo,

You can use the find command.

A simple command as below will find files
that all have permissions as 555

# find /opt -perm -555 | tee /tmp/file.out

Of course you can make them more complex if
you wish, but here is one to get you started.

Regards
Michael
Anyone for a Mutiny ?
Shahul
Esteemed Contributor

Re: Using the find command to find all executable files.


Hi

This script U can use for finding out the executables in ur server.

cd /
for i in `find .`
do
if test -x $i && test -f $i
then
ls >> /tmp/exelist
fi
done

I hope this will full fill ur requirement.

Shahul

Shahul
Esteemed Contributor

Re: Using the find command to find all executable files.


Hi

Now all executables will be listed in /tmp/exelist.


Shahul
Laurent Paumier
Trusted Contributor

Re: Using the find command to find all executable files.

Just to add to Michael's answer, you can add the '-type f' switch to remove directories/symlinks from the output :

find / -type f -perm -555
Ravi_8
Honored Contributor

Re: Using the find command to find all executable files.

find / -perm -555 -print
never give up
Magdi KAMAL
Respected Contributor

Re: Using the find command to find all executable files.

Hi Joanne,

The following script do what you need :


rm /tmp/executableFiles.log > /dev/null 2>&1
allFiles=`find / -name "*" -print`
for currentFile in $allFiles
do
isExecutable=`file $currentFile ? grep executable`
if [[ $isExecutable != "" ]]
then
echo $currentFile >> /tmp/executableFiles.log
fi
done
Klaus Crusius
Trusted Contributor

Re: Using the find command to find all executable files.



find . -type f -exec test -x {} \; -print
There is a live before death!
James R. Ferguson
Acclaimed Contributor
Solution

Re: Using the find command to find all executable files.

Hi Joanne:

If you want to traverse all direcories on your server looking for executable permissions, regardless of other permission bits, do this:

# find / -xdev -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \)

This search returns only files (not directories, etc.) and will not cross mountpoints.

...JRF...
Mladen Despic
Honored Contributor

Re: Using the find command to find all executable files.

Joanne,

I like JRF's answer.

On the other hand, if you want a list of all executable files, regardless of their permissions, you can try something like:

find / -type f | while read -r file
do
file "$line"
done | grep -e exec -e commands

If you want to capture other types of files, you can
omit the grep part, save the output (it will contain a list
of all files on your system) to a file, then view the output and decide what types of files you would like to have extracted from this list (by using grep, etc).

My point is that there may be executables that have
no "execute" permission set. You may also have plain data files with 777 permission (so you won't be able to "run" them). Then, you can have scripts with read
only permission, but one can execute them via "sh", etc.

I guess the answer to your question depends on what you really want to do. I hope this helps a bit.

Mladen




Mladen Despic
Honored Contributor

Re: Using the find command to find all executable files.

Correction - this little script:

find / -type f | while read -r file
do
file "$line"
done | grep -e exec -e commands

is supposed to be:

find / -type f | while read -r file
do
file "$file"
done | grep -e exec -e commands
Joanne Keegan
Regular Advisor

Re: Using the find command to find all executable files.

Thanks to all that replied. I really appreciate your help.

Jo
Bill Thorsteinson
Honored Contributor

Re: Using the find command to find all executable files.

The command

find / -type f -perm +111

will find all files with any executeable bits set. If you
are runing samba this will include most files on your
shares. You will may miss some scripts that are run
by passing them as arguments to commands
like sh, perl, and awk as they don't need the
execute permission bit set.