I wants to get the names of execute files in some directory in Linux. How can I do it?
I tried to use opendir like this:
dir = opendir(directoryName);
I need to get only the names of the execute files. I programming in C.
thanks :)
I wants to get the names of execute files in some directory in Linux. How can I do it?
I tried to use opendir like this:
dir = opendir(directoryName);
I need to get only the names of the execute files. I programming in C.
thanks :)
You should define what you mean by executable files.
That could be any file with its execute bit (it is the owner, group, or other) set. Then test with access(2) & X_OK
and/or use stat(2).
That could also be only ELF executables. See elf(5); then the issue might be to check that a file could indeed be executed, which might be difficult (what about missing library dependencies? or ill-formed ELF files?). Maybe use libelf (and/or libmagic to do the equivalent of file(1) command).
To scan recursively a file tree, use nftw(3); to scan just a directory use opendir(3) & readdir(3) (don't forget the closedir
!), then you'll probably need to build the complete file path from each directory entry (perhaps using snprintf(3) or asprintf(3))
See also Advanced Linux Programming