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