LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   File permissions in bash scripting (https://www.linuxquestions.org/questions/linux-newbie-8/file-permissions-in-bash-scripting-4175466810/)

vignesh_murali2003 06-20-2013 09:35 PM

File permissions in bash scripting
 
Can you guys give me a simple bash script to set the file permissions of the newly created files to 750 if not then set to it.Thanks.

TB0ne 06-20-2013 09:42 PM

Quote:

Originally Posted by vignesh_murali2003 (Post 4975751)
Can you guys give me a simple bash script to set the file permissions of the newly created files to 750 if not then set to it.Thanks.

No. But you can write it yourself, using any of the VERY easily found scripting tutorials. If you get stuck, we will be happy to help, but you need to show effort of your own.

evo2 06-20-2013 09:43 PM

Hi,

you can check and set file permissions with a one liner like.
Code:

#/bin/sh
[ "$(stat -c %a $1)" = "750" ] || chmod 750 $1

However you mention "newly created files" so perhaps you should read up on umask.

Evo2.

vignesh_murali2003 06-21-2013 11:28 AM

Hi,

Will the below script helps

#!/bin/bash
find <folder location> -type d -perm 750
find <file location> -type f -perm 640
fi;

rtmistler 06-21-2013 03:20 PM

Why aren't you setting your umask? That's what it's for.


All times are GMT -5. The time now is 07:15 AM.