The Mastering Emacs ebook cover art

Emacs 28 Edition is out now!

Read a Free Sample

Learn More

Make script files executable automatically

Quick trick to force all shell scripts to have the execute bit set on file save

You can force Emacs to make a file executable (respecting your umask settings) if Emacs considers it a script. To determine if it is a script, Emacs will look for the hash-bang notation in the file and treat it as a script if it finds it.

Add this to your init file and Emacs will then make the file executable if it is a script.

(add-hook 'after-save-hook
  'executable-make-buffer-file-executable-if-script-p)

Further Reading

Have you read my Reading Guide yet? It's a curated guide to most of my articles and I guarantee you'll learn something whether you're a beginner or an expert. And why not check out my book?

Subscribe to the Mastering Emacs newsletter

I write infrequently, so go on — sign up and receive an e-mail when I write new articles