[solved] chmod and chown help?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Minty_64
Level 3
Level 3
Posts: 101
Joined: Mon Jun 30, 2014 3:18 am

[solved] chmod and chown help?

Post by Minty_64 »

hello fellow mint users!

I'm trying to change the properties of folders/files recursively threw a script using chmod and chown, I know that one can just right click -> properties -> permissions -> change things the way I want them then apply to enclosed files, but I want to be able to do so with a script without opening folders and properties all the time.
so far I have the fallowing script that does not work:

Code: Select all

#!/bin/bash

sudo chown username:groupname ~/filename -R && sudo chmod -x ~/filename -R 

read -p "finished"
my problem is that in my head that code should change the owner, the group, as well as make all the files none executable, but what I end up with is with wonky permissions with folder properties and files I cannot access.

anyway thanks in advance if you help me with this problem I'm having, I'm trying to optimise my time with scripts.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
We cannot solve our problems with the same thinking we used in creating them - Albert Einstein
1.618

Re: chmod and chown help?

Post by 1.618 »

I think the problem might be you have placed the " -R " argument in the wrong place

see if this makes a difference

Code: Select all

#!/bin/bash

sudo chown -R username:groupname ~/filename  && sudo chmod -R -x ~/filename 

read -p "finished"
User avatar
Minty_64
Level 3
Level 3
Posts: 101
Joined: Mon Jun 30, 2014 3:18 am

Re: chmod and chown help?

Post by Minty_64 »

1.618 wrote:I think the problem might be you have placed the " -R " argument in the wrong place

see if this makes a difference
thank you for the quick reply
sadly nothing change with the change.
I seem to think something about chmod running on folders changes the owner -> folder access, to "list, create/delete, no access" as I omitted chmod from the script with a # and chown alone doesn't cause the error.
We cannot solve our problems with the same thinking we used in creating them - Albert Einstein
niowluka

Re: chmod and chown help?

Post by niowluka »

You shouldn't remove x from a directory, as it makes its contents inaccessible. That's why your permissions look wonky.

Use a combination of find and chmod to remove x from files only instead, something like:

Code: Select all

find ~/filename -type f -exec chmod -x {} \;
Habitual

Re: chmod and chown help?

Post by Habitual »

Minty_64 wrote:
1.618 wrote:I think the problem might be you have placed the " -R "
Also "-R" is unnecessary on a single file.
User avatar
Minty_64
Level 3
Level 3
Posts: 101
Joined: Mon Jun 30, 2014 3:18 am

Re: chmod and chown help?

Post by Minty_64 »

niowluka wrote:You shouldn't remove x from a directory, as it makes its contents inaccessible. That's why your permissions look wonky.

Use a combination of find and chmod to remove x from files only instead, something like:

Code: Select all

find ~/filename -type f -exec chmod -x {} \;
thanks, this works! :D
We cannot solve our problems with the same thinking we used in creating them - Albert Einstein
Locked

Return to “Scripts & Bash”