LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   creating directories with owner/permissions that stick (https://www.linuxquestions.org/questions/linux-newbie-8/creating-directories-with-owner-permissions-that-stick-602829/)

amg_ 11-27-2007 05:08 PM

creating directories with owner/permissions that stick
 
i have done this before when setting up squid but can not remember or find the command.
I would like to create directories with owners/permissions that stick. By that i mean:
mkdir /store
chown newowner /store
chmod 770 /store
mkdir /store/1
mkdir /store/2

is it possible (umask?)for /store/1 and /store/2 to end up with newowner and 770 during the mkdir process? Is there a command that will tell /store that every directory created under /store should have newowner and 770?

I have been lurking for a while and found this forum to be very helpful.

Thanks ahead.

chrism01 11-27-2007 05:36 PM

Do the mkdirs first, the use the -R switch (recursive) on the chmod & chown cmd. Don't forget the grp owner eg
chown -R owner:grp somedir

amg_ 11-27-2007 05:40 PM

thanks for the quick response.

I was looking for something besides a recursive. I remember a swith or a sticky permission of some sort that would say that anything under that certain directory would inherit permissions and owner from the parent.

thanks anyway.

chrism01 11-28-2007 12:02 AM

Sounds like your confusing it with the 'sticky' bit. See section 6 here: http://www.zzee.com/solutions/unix-p...s.shtml#setuid

jschiwal 11-28-2007 12:11 AM

Yes. The owner of a directory can set the suid and sgid of the directory. Files created by other users will then inherit the owner and group of the parent directory. The permissions on a new file or directory will be masked according to your umask setting.

---
update:
I tried it out with a directory I created on in my home directory. I created it as root and gave it 7777 permissions. A file I created there as a regular user had the group ownership of root but not the ownership. A directory I created there had the group of root but I was the owner.
There may be a capability setting that doesn't allow suid on directories; and maybe there's a good reason why.
---
If you have a directory structure that you want to create, you could use brace expansion to do it, and then use chown and chmod recursively.

mkdir -p store/{1..10}
This will create directory "store" with ten subdirectories "1".."10".


All times are GMT -5. The time now is 10:03 AM.