cancel
Showing results for 
Search instead for 
Did you mean: 

dir *.exe ?

SOLVED
Go to solution
Maaz
Valued Contributor

dir *.exe ?

Hi
if i wana see only executable binaries what should i do??
In Windows it is acheived by issuing "dir *.exe"

Regards
Maaz
7 REPLIES
Nicolas Dumeige
Esteemed Contributor

Re: dir *.exe ?

Unix or Linux doesn't rely on file extension. To make a file executable, you just set the executable bit on it.
man chmod
To list only executable file :
use the perm option of find or display option of ls.
You can also use the command
file *
to get a descritpion of what's in your directory/
All different, all Unix
Martin P.J. Zinser
Honored Contributor
Solution

Re: dir *.exe ?

Hello Maaz,

ls -F | grep '*' is one way to do it.

Greetings, Martin

Karthik S S
Honored Contributor

Re: dir *.exe ?

This will list you all the executables under the current directory,

for i in *; do if [ -x $i ]; then ll $i; fi; done

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Mark Grant
Honored Contributor

Re: dir *.exe ?

Theonly way you can really be sure is to do "file " and read the output.

However, generally speaking, all your binaries are probably in one of a few places. /bin, /usr/bin, /sbin or /usr/local/bin. The common theme here being "bin".
Never preceed any demonstration with anything more predictive than "watch this"
Hein van den Heuvel
Honored Contributor

Re: dir *.exe ?

did you want to list 'real executables' or executable shell scripts also?


The -x operator is (of course!) also available in perl. For example:

perl -e 'while (<*>) { print "$_\n" if (-x $_) }'

Be sure to check out the 'file' command though as it really 'knows' stuff.
Actually, it does not, but it does a stellar job guessing :-).

file * | awk -F: '/executable/{print $1}'

Using file will also protect against false positives (a text file marked +x) and false negatives (an executable marked -x).
Witness:

# file *
README: ASCII English text
etc_init.d_rexd: Bourne shell script text
kit.LINUX-IA32.tar: GNU tar archive
kit.Tru64UNIX.tar: POSIX tar archive
kit.hpux-ia64.tar: POSIX tar archive
kit.hpux-pa.tar: POSIX tar archive
rex: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dd
rexd: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dd
sbin_init.d_rexd: a /sbin/sh script text

# ls -F * | grep "*"
rex*
rexd*

# perl -e 'while (<*>) { print "$_\n" if (-x $_) }'
rex
rexd

# chmod +x README
# file * | awk -F: '/executable/{print $1}'
rex
rexd

# perl -e 'while (<*>) { print "$_\n" if (-x $_) }'
README
rex
rexd

# chmod -x rex
# perl -e 'while (<*>) { print "$_\n" if (-x $_) }'
README
rexd

# file * | awk -F: '/executable/{print $1}'
rex
rexd

file rules!

Cheers,
Hein.

Elmar P. Kolkman
Honored Contributor

Re: dir *.exe ?

It depends on your definition of executable binaries... Using the -x option or looking at the permissions is not enough if you're not interested in shell scripts or data files that have the execute bit on by accident.

But there is another problem: you can have binaries that are not executable by the user doing the test. You won't see those files, but they might show up if the file command can read them...

Problem with the find command might be it goes down into subdirectories. Something the dir command won't do, unless you specified the /s option.

So, the 'script' would become something like this:
ls -F | grep '[*]$' | sed 's|[*]$||' | while read f
do
if file $f | grep -q executable
then
echo $f
fi
done
Every problem has at least one solution. Only some solutions are harder to find.
Maaz
Valued Contributor

Re: dir *.exe ?

Hi Gurus, ...So Nice of u all
Many Thanks

Maaz