LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 02:21 PM   #1
sabresong
Member
 
Registered: Feb 2011
Location: Asheville, NC, USA
Distribution: Fedora 19
Posts: 35
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, 02:29 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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, 02:34 PM   #3
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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, 08:16 PM   #4
sabresong
Member
 
Registered: Feb 2011
Location: Asheville, NC, USA
Distribution: Fedora 19
Posts: 35
Blog Entries: 1

Original Poster
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 08:26 AM
Setting default permissions for folder dickohead Linux - General 1 04-17-2006 10:55 AM
Default directory permissions gwroy20 Linux - Software 7 08-28-2005 05:30 PM
Default Directory Permissions tranquil222 Linux - Software 8 05-20-2004 06:10 PM
Setting default permissions for user loadedmind Slackware 3 11-05-2003 04:24 PM


All times are GMT -5. The time now is 06:35 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration