Skip to content

Instantly share code, notes, and snippets.

@ktomk
Created June 13, 2018 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktomk/b2442a94a3f080ca05539b2fbc5ef914 to your computer and use it in GitHub Desktop.
Save ktomk/b2442a94a3f080ca05539b2fbc5ef914 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# de-execute all executable files that are either zero width or don't have a shebang (Magic Line)
#
# note: no explicit non-binary check ( -not -exec grep -vIq . "{}" \; )
#
echo -n "before: "; find . \( -name '.git' -o -name 'bin' \) -prune -o -type f -executable -print | wc -l
find . \( -name '.git' -o -name 'bin' \) -prune -o -type f -executable \
\( -size 0 -o -exec /bin/bash -c 'head -n 1 {} | grep -vq ^#!' \; \) -exec chmod -x {} \;
echo -n "after: "; find . \( -name '.git' -o -name 'bin' \) -prune -o -type f -executable -print | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment