Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-28-2013, 12:39 AM   #1
LQ Newbie
Registered: Feb 2013
Posts: 2

Rep: Reputation: Disabled
How to set permissions to the newly generated files in the directory

I'm writing a shell script for MySQL database incremental backup using binary logs. The binary logs are collected in /usr/local/mysql/data/ directory. I have set all permissions to this directory data (chmod -R 777). When I did this, all files in the directory data were granted read,write and execute permissions.
But, when I flush logs, new logs get generated in data directory for which this permissions are not applied. Is there a way where I can apply the same permissions to this files as well. How can I do this?
Old 02-28-2013, 01:35 AM   #2
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
First thing is, you should not give 777 permission recursively to any directory, as it means that everyone who can access your system, will be able to access, modify, and alter the log files. So change it to:
~$ chmod -R 775 /usr/local/mysql/data
Second, any newly created file gets it's permissions assigned from what umask value is set for the file creator. But changing umask to 000 for file owner is not at all a good a recommended way. So just drop this idea.

Third, in your present case, I'd suggest you to apply SGID on the parant directory i.e. on /usr/local/mysql/data, and anyone whom you wish to allow to read content inside it, add to the main group of this directory.
~$ ls -ld /usr/local/mysql/data              # Checking owner and group of /usr/local/mysql/data
drwxrwxr-x   ....   testowner    testgroup .... /usr/local/mysql/data

~$ chmod g+xs /usr/local/mysql/data          # Adding SGID on directory

~$ usermod -G testgroup testuser1 testuser2  # Adding users to the main group i.e. testgroup
Using SGID, any newly created file inside it will inherit the main group of the directory. So the new log file will also have the same group as that of parant dir. has. Thus, anyone who's in this mail group i.e. testgroup, will be albe to read, write, and execute the content.

Last edited by shivaa; 02-28-2013 at 01:39 AM. Reason: Grammatical mistake


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
Changing file permissions of generated /var/log files jeriryan Linux - Security 2 06-13-2012 10:25 AM
inherit permissions of the parent directory in newly created file abhijit_mohanta Linux - Newbie 1 09-10-2009 07:45 PM
Newly created File/directory permissions? redrobin77 Fedora 3 11-14-2005 05:55 AM
How to set permissions for newly created dirs? z-vet Linux - General 2 12-04-2004 09:06 AM
How to permanently set permissions on all files created in a directory? BrianK Linux - General 8 06-24-2004 05:06 PM > Forums > Linux Forums > Linux - Newbie

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

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