[CLUE-Talk] create mask for a directory?

Jim Ockers ockers at ockers.net
Sat Mar 27 15:33:46 MST 2004


Hi Dave,

Dave Price wrote:
>
> Is there a way to force files created in a spcific directory to be world
> readable by default.
> 
> I have seen a reference to a create mask in smb.conf, but I am not
> referring to samba here - just attachments saved from within a my mutt
> mail reader.

As you know the umask controls the create mask for files and directories.
If you could somehow check the working directory using pwd then you could
set the umask in that particular directory to world-readable (umask 022), 
and set the umask for every other directory to owner-only readable (umask 077).

I use tcsh but this principle probably applies to bash.  If you make
the "cd" command (to change directories) be an alias to a shell
script, then you can match the pwd with your specific directory and
set the umask accordingly.

For example, here is what I use in tcsh to make a custom prompt string
using awk.  This is in my .cshrc.

alias setp 'set prompt = "[%h] %M:`pwd | awk -F/ -f ~/.prompt.awk` > "'
alias cd "cd \!*; setp"

For the record, the file .prompt.awk contains this:

 { print $0 }
 #{if ($3 == "ockers") {for (i=3; i<=NF; i++) printf("/%s", $i); print ""} } 
 #{if ($3 != "ockers") print $0}

You can do more complicated stuff with awk as you can see; I just have it
set to print the entire string ($0) right now.  I used to have awk match
'ockers' and change the prompt accordingly if that was in the pwd.  I was
compensating for overly long nested home directory names on a particular 
system I used to use.

Instead of using awk to generate a prompt string, you could send the
pwd output to a shell script that sets the umask.  I'm not sure if the
umask is inherited by the parent shell if it's executed by a sub-shell
but you could try it.

I know I'm not telling you exactly how to do it, but I think with this
technique you can do whatever you want every time you change directories.

Hope this helps,
Jim

-- 
Jim Ockers, P.Eng. (ockers at ockers.net)
Contact info: please see http://www.ockers.net/



More information about the clue-talk mailing list