LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-20-2013, 10:35 PM   #1
vignesh_murali2003
LQ Newbie
 
Registered: Jun 2013
Posts: 24

Rep: Reputation: Disabled
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.
 
Old 06-20-2013, 10:42 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,944

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by vignesh_murali2003 View Post
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.
 
Old 06-20-2013, 10:43 PM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
1 members found this post helpful.
Old 06-21-2013, 12:28 PM   #4
vignesh_murali2003
LQ Newbie
 
Registered: Jun 2013
Posts: 24

Original Poster
Rep: Reputation: Disabled
Hi,

Will the below script helps

#!/bin/bash
find <folder location> -type d -perm 750
find <file location> -type f -perm 640
fi;
 
Old 06-21-2013, 04:20 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,102
Blog Entries: 10

Rep: Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524
Why aren't you setting your umask? That's what it's for.
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting: Menu from file sociopathichaze Programming 2 05-30-2011 10:47 PM
bash scripting...is a file also a string? Daravon Linux - Newbie 3 09-03-2008 04:38 AM
Bash Scripting Empty file john8675309 Linux - Software 2 08-08-2007 05:05 PM
bash scripting testing for file exvor Programming 4 08-08-2007 04:42 PM
bash scripting read from file cadj Programming 2 02-29-2004 11:42 PM


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

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