PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > select executables
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

select executables

Réponse
 
LinkBack Outils de la discussion
Vieux 13/03/2008, 15h36   #1
Aggelidis Nikos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut select executables

Hi,

is it possible to select all executable files from a directory tree?

I tried using find with -exec but i couldn't make it work

find -type f -exec
if test -x "{}"
then
echo "found an executable"
fi
\;

i tried making a function like this

function Qexe ()
{
if test -x "$1"
then
echo "found an executable"
fi
}

and then call it from find like this

find -type f -exec Qexe "{}" \;

but again it didn't work.


thanks in advance for your ,
-nicolas

PS: i think that my question could be generalized if it is possible to
you your own predicate in find...
  Réponse avec citation
Vieux 13/03/2008, 15h46   #2
Florian Kaufmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select executables

man find
then go to the -perm option
there are also some examples in the examples section


  Réponse avec citation
Vieux 13/03/2008, 15h51   #3
Aggelidis Nikos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select executables

> All your examples use -type f, which finds *all* the regular files, not
> just executables.
> To find executables, you can use the -perm option:
>
> find -type f -perm /u+x,g+x,o+x
>
> (or any variation therein - for example, if you want only
> owner-executables etc.)
>
> man find for the details.


thank you guys for your answers, i did read the manual... the problem is
that i would like to use my predicate-function and i can't get it to
work. Is this possible?

thanks for your time,
-nicolas
  Réponse avec citation
Vieux 13/03/2008, 15h54   #4
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select executables

Aggelidis Nikos wrote:

> Hi,
>
> is it possible to select all executable files from a directory tree?
>
> I tried using find with -exec but i couldn't make it work


All your examples use -type f, which finds *all* the regular files, not just
executables.
To find executables, you can use the -perm option:

find -type f -perm /u+x,g+x,o+x

(or any variation therein - for example, if you want only owner-executables
etc.)

man find for the details.

  Réponse avec citation
Vieux 13/03/2008, 16h49   #5
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select executables

Aggelidis Nikos wrote:

> thank you guys for your answers, i did read the manual... the problem is
> that i would like to use my predicate-function and i can't get it to
> work. Is this possible?


Ah, then I probably misunderstood your question in the first place.
You want to find all files, and filter out the executables using a function
or predicate of yours.

(The following is tested under bash)

Well, you can use an external script:

$ cat ckexec.sh
#!/bin/bash

if [ -x "$1" ]; then
echo "$1 is executable"
else
echo "$1 is not executable"
fi

$ ls -l
total 20
-rwxr-xr-x 1 pk users 98 2008-03-13 15:58 ckexec.sh
-rwxr-xr-x 1 pk users 8 2008-03-13 09:10 configure
-rwxr-xr-x 1 pk users 22 2008-03-13 14:14 f
-rwxr-xr-x 1 pk users 23 2008-03-13 14:14 f2
-rw-r--r-- 1 pk users 2164 2005-12-18 17:46 README

$ find -type f -exec ckexec.sh '{}' \;
../README is not executable
../configure is executable
../f is executable
../f2 is executable
../ckexec.sh is executable

Apparently, -exec does not accept a direct function name (but I stand to be
corrected):

$ function ckexec { if [ -x "$1" ]; then echo "$1 is executable"; else
echo "$1 is not executable"; fi; }
$ export -f ckexec
$ find -type f -exec ckexec '{}' \;
find: ckexec: No such file or directory
find: ckexec: No such file or directory
find: ckexec: No such file or directory
find: ckexec: No such file or directory
find: ckexec: No such file or directory

Instead, you can use almost arbitrary code by using bash -c:

$ find -type f -exec bash -c "ckexec '{}'" \;
../README is not executable
../configure is executable
../f is executable
../f2 is executable
../ckexec.sh is executable

or even

$ find -type f -exec bash -c "if [ -x '{}' ]; then echo '{}' is executable;
else echo '{}' is not executable; fi;" \;
../README is not executable
../configure is executable
../f is executable
../f2 is executable
../ckexec.sh is executable

  Réponse avec citation
Vieux 13/03/2008, 23h50   #6
Aggelidis Nikos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select executables

> Instead, you can use almost arbitrary code by using bash -c:
>


thank you for your . i wasn't aware of bash -c and it really me
complete my task!
  Réponse avec citation
Vieux 14/03/2008, 11h27   #7
Rakesh Sharma
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: select executables

On Mar 13, 7:36 pm, Aggelidis Nikos <aggelidis.n...@gmail.com> wrote:
> Hi,
>
> is it possible to select all executable files from a directory tree?
>
> I tried using find with -exec but i couldn't make it work
>
> find -type f -exec
> if test -x "{}"
> then
> echo "found an executable"
> fi
> \;
>
> i tried making a function like this
>
> function Qexe ()
> {
> if test -x "$1"
> then
> echo "found an executable"
> fi
>
> }
>
> and then call it from find like this
>
> find -type f -exec Qexe "{}" \;
>
> but again it didn't work.
>
> thanks in advance for your ,
> -nicolas
>
> PS: i think that my question could be generalized if it is possible to
> you your own predicate in find...




find . \
-type f \
\( -perm -u+x -o -perm -g+x -o -perm -o+x \) \
-exec echo {} is executable \; \
-prune \
-o \
-type f \
-exec echo {} is not executable \;
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h11.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14115 seconds with 15 queries