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

I keep creating practice perl scripts in a linux directory using vi <filename> and need to chmod 751 <filename> before I can run it as I wish to. I'm sure there is a simple way to default my permissions or config them at creation, but I'm not familiar with it - ayuda me por favor.

share|improve this question
Why don't you write a script to create a new one with the correct permissions? #!/bash/bin touch $1; chmod 751 $1 – tjameson Apr 5 '11 at 19:19
up vote 2 down vote accepted

A simple solution would be to make a bash alias for vi which will first create the file and then change it's permissions before opening it. Use something easy to remember, like vix (x for executable bit):

e.g. (untested):

function vix {
        touch $1
        chmod 751 $1
        vi $1

Note that aliasing vi itself is a bad idea as many other programs call on it directly, which may cause issues with your system.

share|improve this answer
Re "aliasing vi itself is a bad idea as many other programs call on it directly": They would be unaffected by aliases or shell functions. (system() uses sh -c which ignores all rc files, and exec*() skip the shell entirely.) ...edit: apparently, exporting a shell function does affect sh -c. – grawity Apr 5 '11 at 19:39
Depends on how the script/program is invoking it, but generally correct. – John T Apr 5 '11 at 19:41
all solid points -- now I know I'm not not missing a hidden ability of vi itself. I use both root & user dev on this system - which files do I need to edit to cover both? – mjb Apr 5 '11 at 21:00

751 doesn't make much sense for scripts - it allows "others" to execute the file, but not read it. (For scripts, which don't get setuid honored, this is impossible.)

To set default permissions for newly created files, you can use either umask (per-process) or default ACLs (per-directory). But they both can only remove permission bits; neither of them will add the "executable" bit automatically unless the program specifically asks for it. (For example, fopen() always requests 0666, the sane default for files.)

You will have to follow mjb's suggestion of writing a script that creates a file and immediately updates its permissions. Alternatively, run your practice scripts like perl, which does not require the executable bit.

share|improve this answer
good points - just so you know, I don't want coworkers who I may share the code w/being able to read the content of the file, but I don't mind if they run it. Hint that 1 at the end. – mjb Apr 5 '11 at 20:58
@mjb: As I said in the first paragraph of my answer, I'm not sure how that could possibly work. – grawity Apr 6 '11 at 5:57

You must log in to answer this question.

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