Reputation: 323
Is it possible to have a bash script invoked with root permissions to run different commands with different privileges?
Right now i have a script which runs a C-program with root permissions and creates a folder and some files which i want to have non-root permissions. Looking at the man page i see that the mkdir command takes a permissions parameter but i was wondering whether there's a smarter way of doing this.
Upvotes: 0
Views: 87
Reputation: 766
Have a look at the man pages for the chmod
and chown
commands. Depending on what you are trying to do, either one of these should be our solution.
If you want to change the directory ownership to a user/group other than root, use chown -R user:group [directory]
to recursively change ownership. If you just want the permissions changed, but with root still in ownership then use chmod -R 754 [directory]
; keep in mind you will need to alter the permissions to suit your needs.
Upvotes: 0