Skip to content

Instantly share code, notes, and snippets.

@ktomk
Created June 13, 2018 13:00
Show Gist options
  • Select an option

  • Save ktomk/b2442a94a3f080ca05539b2fbc5ef914 to your computer and use it in GitHub Desktop.

Select an option

Save ktomk/b2442a94a3f080ca05539b2fbc5ef914 to your computer and use it in GitHub Desktop.

Revisions

  1. ktomk created this gist Jun 13, 2018.
    13 changes: 13 additions & 0 deletions git-fix-executables.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/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