I need to find all executable files from /bin. How to do it using
find . -executable
and how to check if the file is script (for example, sh, pl, bash)?
#!/bin/bash
for file in `find /bin` ; do
if [ -x $file ] ; then
file $file
fi
done
and even better to do
find /bin -type f -perm +111 -print0 | xargs -0 file
find /bin/ -executable returns all executable files from /bin/ directory.
To filtering extension there are usable -name flag. For example, find /bin/ -executable -name "*.sh" returns sh-scripts.
UPD:
If file is not a binary file and do not have extension, it's possible to figured out it's type from shabang.
For example find ~/bin/ -executable | xargs grep --files-with-matches '#!/bin/bash' returns files from ~/bin/ directory, which contains #!/bin/bash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With