Skip to content

Instantly share code, notes, and snippets.

@rich-97
Created December 24, 2016 20:35
Show Gist options
  • Save rich-97/9ceec2af7af2e2919170c6e89ae049eb to your computer and use it in GitHub Desktop.
Save rich-97/9ceec2af7af2e2919170c6e89ae049eb to your computer and use it in GitHub Desktop.
List all binaries of directories in $PATH.
#!/bin/bash
list=${PATH//:/' '}
list=${list//\}/' '}
list=${list//\{/' '}
color () {
if [ -z $1 ]; then
tput setaf 1
else
tput setaf $1
fi
}
lsbin () {
sum=0
for i in $list; do
if [ -d $i ]; then
files=$(ls $i)
else
color; echo "Directory no valid."
continue
fi
for j in $files; do
if [ -x $i/$j ]; then
let sum+=1
color 2; echo -n $j
color 3; echo " $(du -k $i/$j | cut -f 1)kb"
fi
done
done
color 6; echo "total: $sum"
}
lsbin | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment