LinuxQuestions.org
Visit Jeremy's Blog.
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 07-04-2007, 05:30 AM   #1
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41

Rep: Reputation: 15
INSTALL command in linux


Hello All,

I am not sure whether I am posting my question in correct thread or not. Sorry if I am not doing it correct. My problem is, I want set the permissions for existing directory structure in linux. For example,

/home/bala/project/ ---- I want to set 755 for /home,/home/bala and /home/bala/project.


I was using install command with --mode so that, I can set it if those directories are not already present. But if that directory already present, then also I need to change the permissions. Is it possible using any direct command in linux? Instead of parsing the directories manually and applying chmod?
Please share your ideas with me.

Thanks.

Last edited by Balakrishnan84; 07-04-2007 at 05:31 AM. Reason: install mode
 
Old 07-04-2007, 05:33 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Use chmod with recursive switch:
Code:
chmod -R 755 /home
Next time, first do
Code:
man chmod
or if you aren't sure about the command,
Code:
man -k keyword
 
Old 07-04-2007, 05:44 AM   #3
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by b0uncer
Use chmod with recursive switch:
Code:
chmod -R 755 /home
Next time, first do
Code:
man chmod
or if you aren't sure about the command,
Code:
man -k keyword
Thanks for your suggestion. But...if you apply chmod -R then it will change permissions to all of its contents...I dont want to perform that....
I just want to change only to specific directories...
got it?
 
Old 07-04-2007, 06:51 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Use "find" to track down the directories (-type d). -maxdepth can limit the number of directory levels that are recursively searched. -exec allows for the execution of a chmod on each directory found.

For instance:
Code:
find /home -type d -maxdepth 3 -exec chmod 755 {} \;
This will not affect all the files in those directories (in contrary to chmod -R), but it will affect all directories.

Is that closer to what you want?
 
Old 07-04-2007, 06:57 AM   #5
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by timmeke
Use "find" to track down the directories (-type d). -maxdepth can limit the number of directory levels that are recursively searched. -exec allows for the execution of a chmod on each directory found.

For instance:
Code:
find /home -type d -maxdepth 3 -exec chmod 755 {} \;
This will not affect all the files in those directories (in contrary to chmod -R), but it will affect all directories.

Is that closer to what you want?
Thanks for your idea. But as you know, if I run this under /home then all users' home directory will get read permission for others. so it is an major security issue. I knew that we can just put our own logic to implement what I want....but I was wondering is there any command in linux does that? Because, install -d <dir_path> -m <mode> works on similar way but it wont set the permission if the directory already exists...but i want to do the same even the directory already exists....
Thanks.

Last edited by Balakrishnan84; 07-04-2007 at 06:59 AM.
 
Old 07-04-2007, 07:39 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
Originally Posted by Balakrishnan84
Thanks for your idea. But as you know, if I run this under /home then all users' home directory will get read permission for others. so it is an major security issue. I knew that we can just put our own logic to implement what I want....but I was wondering is there any command in linux does that? Because, install -d <dir_path> -m <mode> works on similar way but it wont set the permission if the directory already exists...but i want to do the same even the directory already exists....
Thanks.
I see what you mean. Well, I don't think there's a command ready-made for that.

Anyway, here's an example script, that takes the full path as only parameter:
Code:
pathStr='';
#cut will cut up the path into its separate elements. As output delimiter, use one of the
#characters in $IFS
pathElem=`echo $1 | cut -d'/' --output-delimiter=' ' -f1-`;
for elem in $pathElem; do
pathStr="${pathStr}/${elem}; #re-constitute the path, adding one element each iteration of loop
if [[ -d ${pathStr} ]]; then
chmod 755 ${pathStr};
fi;
done;
As I haven't tested this completely, you might want to try echo'ing the chmod commands that are issued before actually executing them.

Last edited by timmeke; 07-04-2007 at 07:41 AM.
 
Old 07-04-2007, 11:37 PM   #7
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41

Original Poster
Rep: Reputation: 15
Smile

Thanks a lot for your reply. It works. But I thought we might have a ready made command to do this.. like install -f ....
Thanks again.
 
Old 07-05-2007, 01:25 AM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Commands are usually not more than scripts, provided in a standard location like /bin, /usr/bin,... (except for some internal shell commands). So if you put the script in the right place, you have the "command" you're looking for.
 
Old 07-05-2007, 04:10 AM   #9
Balakrishnan84
Member
 
Registered: Feb 2007
Location: Bangalore, India
Distribution: Fedore Core 6
Posts: 41

Original Poster
Rep: Reputation: 15
I knew it well. Thanks.
 
  


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
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
Ndiswrapper install failure - LBA-Linux "make" command fails petteril Linux - Wireless Networking 1 04-23-2005 08:22 AM
unix command to linux command leonidas Linux - General 1 09-10-2004 12:40 AM
How to install "make" command from rpm on cd 2 - red hat linux 7.0 ZARGON Linux - Newbie 2 08-31-2004 10:53 AM
Command for HD install? gopikrish Linux - Software 1 08-18-2004 12:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:11 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