Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way I can configure my linux box or editor like vim/emacs to automatically give executable file permission to certain file types ?

Currently if I want to write a bash script I need to manually give executable permission. I am looking for a way that whenever I create file having .bash or .sh extension It should give executable permission to that file.

share|improve this question

migrated from Aug 28 '12 at 3:49

This question came from our site for professional and enthusiast programmers.

@JohnWatts sorry I realized after posting question that is should belong to super user. How can I move question to super user. – Vivek Goel Aug 1 '12 at 16:35
I'm actually not sure. I think it will get moved by the close operation automatically. It gets closed here and opened there, once it gets enough votes. – John Watts Aug 1 '12 at 16:38
@VivekGoel you should also be looking at the presence of the magic cookie "hash-bang", not file extension. – event_jr Aug 1 '12 at 16:41
@event_jr thanks – Vivek Goel Aug 1 '12 at 16:58
up vote 9 down vote accepted

Well the Emacs aspect of it definitely does fit on StackOverflow. Here is a bit of code to add to your init file to mark magic number "hash-bang" files executable:

(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
share|improve this answer
Agreed. Almost every Emacs question involves a programmatic elisp solution, so such questions belong here IMO. – sanityinc Aug 2 '12 at 11:17

One vim equivalent:

au BufWritePost,BufFilePost *.sh call system("chmod +x ".expand("%"))
share|improve this answer

vim-eunuch makes files with shebang lines executable, among other things.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .