The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 313,770β€…    Votes:  2β€…
Tags: linux   command-line   bash   find  
Link: πŸ” See Original Answer on Super User ⧉ πŸ”—

URL: https://superuser.com/q/1445393
Title: How can I find only the executable files under a certain directory in Linux?
ID: /2019/06/06/How-can-I-find-only-the-executable-files-under-a-certain-directory-in-Linux_
Created: June 6, 2019
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


I created a function in ~/.bashrc tonight to find executable files not in the system path and not directories:

# Quickly locate executables not in the path
xlocate () {
    locate -0r "$1" | xargs -0 -I{} bash -c '[[ -x "$1" ]] && [[ ! -d "$1" ]] \
        &&  echo "executable: $1"'  _  {}
} # xlocate ()

The advantage is it will search three Linux distros and a Windows installation in under a second where the find command takes 15 minutes.

For example:

$ time xlocate llocate
executable: /bin/ntfsfallocate
executable: /home/rick/restore/mnt/e/bin/llocate
executable: /mnt/clone/bin/ntfsfallocate
executable: /mnt/clone/home/rick/restore/mnt/e/bin/llocate
executable: /mnt/clone/usr/bin/fallocate
executable: /mnt/e/bin/llocate
executable: /mnt/old/bin/ntfsfallocate
executable: /mnt/old/usr/bin/fallocate
executable: /usr/bin/fallocate

real	0m0.504s
user	0m0.487s
sys 	0m0.018s

Or for a whole directory and all it’s subs:

$ time xlocate /mnt/e/usr/local/bin/ | wc -l
65

real	0m0.741s
user	0m0.705s
sys 	0m0.032s
⇧ added display moves icons to extended desktop How can I double the tty font size on a 3840x2160 monitor?  β‡©