Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.