LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-21-2009, 05:55 AM   #1
chesterman
LQ Newbie
 
Registered: May 2009
Posts: 16

Rep: Reputation: 0
force create permissions


is there a way to enforce that a file created on a directory will inherit the owner/groupship of the his parent folder?
 
Old 11-21-2009, 06:50 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,075

Rep: Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777
If you mean with, say, the cp utility then yes you can use the --preserve option; e.g.,
Code:
cp --preserve=all file directory
See the man page.

Hope this helps some.
 
Old 11-21-2009, 07:45 AM   #3
chesterman
LQ Newbie
 
Registered: May 2009
Posts: 16

Original Poster
Rep: Reputation: 0
there is a proccess running as root (i now this is not the good thing to do, but is the way is running now, and it can't be changed in some months) that create tons of files in a folder. i have to sync this files with a twin folder on other machine, but there is no root access by ssh between the 2 machines.

also, in the twin machine, the process is running with limited user (the right thing), so while I can not change this process to run as root on original machine, I want the files it creates have the folder permissions, and not his.
 
Old 11-21-2009, 09:32 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,075

Rep: Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777Reputation: 777
If you can read the files from the other machine (with, say, scp) and have your umask set properly, the files should copy with "your" owner and group; that is, whatever user account is doing the copying will be the owner and group of the copied files and the files will have permission defined by your system umask setting (which probably ought to be 0022 which creates files 0644 and directories 0755).

Hope this helps some.
 
Old 11-21-2009, 10:07 AM   #5
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
If the the directory has the setgid bit set then files created in it will have group ownership of the directory. You can set it like this:
Code:
$ mkdir directory
$ ls -ld directory
drwx------ 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
$ chmod g+s directory
$ ls -ld directory
drwx--S--- 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
When you see the 'S' in the group permissions field it is set correctly for this behaviour.

Just a note, I believe files "moved" into the directory, rather than created in it, will retain their original group.

Last edited by lwasserm; 11-21-2009 at 10:08 AM.
 
Old 11-23-2009, 12:44 PM   #6
chesterman
LQ Newbie
 
Registered: May 2009
Posts: 16

Original Poster
Rep: Reputation: 0
hey, it worked =D
worked just with the files created inside the folder, and just for the groupship. files moved into the folder did not get changed.

tks guys =D
 
Old 11-23-2009, 01:26 PM   #7
chesterman
LQ Newbie
 
Registered: May 2009
Posts: 16

Original Poster
Rep: Reputation: 0
what's the difference between
Code:
drwx--S--- 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
and
Code:
drwx--s--- 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
?
 
Old 11-23-2009, 03:20 PM   #8
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
Quote:
Originally Posted by chesterman View Post
what's the difference between
Code:
drwx--S--- 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
and
Code:
drwx--s--- 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
?
A lower case s indicates the file is also executable for the group. You would probably need that on subdirectories too.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force permissions in a folder geomysterio Linux - Newbie 2 05-28-2009 06:12 PM
C++: force ofstream to create file with iso-8859-1 encoding matiasar Programming 2 04-02-2009 08:56 AM
Samba 'force create mode = 664' ignored (RHEL 5) hillersa Linux - Server 2 03-25-2009 06:34 AM
How does one force directory permissions for existing/new files salieg Linux - Newbie 3 05-12-2004 06:58 AM
force delete/remove and mass file permissions-setting moxieman99 Linux - Newbie 2 02-15-2004 11:43 AM


All times are GMT -5. The time now is 07:02 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration