LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   INSTALL command in linux (https://www.linuxquestions.org/questions/linux-general-1/install-command-in-linux-566543/)

Balakrishnan84 07-04-2007 05:30 AM

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.

b0uncer 07-04-2007 05:33 AM

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
:)

Balakrishnan84 07-04-2007 05:44 AM

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?

timmeke 07-04-2007 06:51 AM

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?

Balakrishnan84 07-04-2007 06:57 AM

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.

timmeke 07-04-2007 07:39 AM

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.

Balakrishnan84 07-04-2007 11:37 PM

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.:)

timmeke 07-05-2007 01:25 AM

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.

Balakrishnan84 07-05-2007 04:10 AM

I knew it well. Thanks.


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