LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2012, 01:21 PM   #1
sabresong
Member
 
Registered: Feb 2011
Location: Asheville, NC, USA
Distribution: Fedora 19
Posts: 36
Blog Entries: 1

Rep: Reputation: 2
Setting default permissions for new files under a directory


I'm trying to find a way to set default permissions for newly created files in a specific directory.

I have a directory called scripts, in which I write scripts while I teach myself shell scripting and python. I need all these scripts to be executable. Right now I do it at file creation:

Code:
touch newfile && chmod +x newfile && vi newfile
What I'd like to do is set the default permissions so that any new file created under the scripts directory is automatically executable. I've read info on umask, but if I understand it correctly, that would make all new files executable, not just the ones under scripts.

Is there a way to set default permissions for new files under a specific directory?
 
Old 07-02-2012, 01:29 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
umask is the shell built-in that controls new file perms. Not sure of any other way to make it apply to one directory only.

However, if this is something you really wanted to do you could use this as a learning experience to create a watchdog script via Perl/Python or even bash to watch for newly created files and make them executable. (Might want to be careful the way you write it to make sure it doesn't over-utilize the server.)
 
Old 07-02-2012, 01:34 PM   #3
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Or you could alternatively create a bash script that you can use to create files for you.

Such as:

Code:
./createnewscript.sh newscriptfilename.sh
Where ./createnewscript.sh is a bash script that takes arguments and creates the file for you.
 
Old 07-02-2012, 07:16 PM   #4
sabresong
Member
 
Registered: Feb 2011
Location: Asheville, NC, USA
Distribution: Fedora 19
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 2
Thanks for the answer, and for the suggestions that I script what I needed. It took a bit of digging, since I'm kind of new to this aspect of Linux, but I was able to write a simple bash script using inotify. I don't yet know enough to know how much of a load it puts on the server, but here's what I came up with:

Code:
while true ; do
    # define an event
    event=`inotifywait -r -e create -q $HOME/scripts`

    # parse the event into DIR, TAGS, FILE
    set -- $event
    event_dir=$1
    event_tags=$2
    event_file=$3

    # set file executable
    chmod +x $event_dir$event_file
done
I put it into a function, added it to .bashrc, and it works perfectly.

Thanks again!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting default permissions ahh Linux - General 6 01-24-2007 07:26 AM
Setting default permissions for folder dickohead Linux - General 1 04-17-2006 09:55 AM
Default directory permissions gwroy20 Linux - Software 7 08-28-2005 04:30 PM
Default Directory Permissions tranquil222 Linux - Software 8 05-20-2004 05:10 PM
Setting default permissions for user loadedmind Slackware 3 11-05-2003 03:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration