Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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

2 Answers 2

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
1  
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 foo.pl, 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.