Score:1

How to change a folder's permissions and owners?

cf flag

I just simply want to give the same attributes I have for "cars" directory to "animals" directory. In other words, how can I de-privilege that specific file in terms of permissions?

drwxrwxrwx 14 root  root  4096 Nov 26 19:41 animals
drwxr-xr-x  2 user  user  4096 Nov 16 16:59 cars
Score:3
ru flag

sudo chown -v user:user /path_to/animals changes both the folder owner and the group from root:root to user:user.

Now that root is no longer the owner, sudo is not needed anymore.

chmod -v 755 /path_to/animals changes the folder's access permissions to the same ones as cars.

If there are files and folders inside the animals folder and you wish to change their ownership and permissions too, add an R next to the -v option so that the commands look like:
sudo chown -vR user:user /path_to/animals
chmod -vR 755 /path_to/animals.

Typing something like file and folder permissions linux on Google, will give you plenty of results on how they work.

Score:1
sy flag

Use chown command for the ownership, and add -hR flag for all its sub-files/folders.

For example, make animals and all files/folders under that folder owned by user and group user via command:

sudo chown user:user -hR animals

TIP: remove -hR so it applies to that folder only.

Use chmod command for file/folder permission, with following flags:

  • u means user(owner), g means group, o means others, a for all.
  • r for read permission, w for write, and x for execute.

For example, grant read and write permission for user and group, but only read permission for others, use (add sudo if you're not owner):

chmod u=rw,g=rw,o=r FILE

Grant read and write permission for all:

chmod a=rw FILE

or add read&read permission for all: chmod +rw FILE

Remove write permission for others (for that folder only):

chmod o-w FOLDER

Add read/write/executable for user and group, but no permission for others, for specified folder and all sub-files/folders:

chmod -R ug+rwx,o-rwx FOLDER

You can also use numbers along with chmod command to change permissions.

  • 1 = executable
  • 2 = write permission.
  • 4 = read permission.
  • 5 = 1+4 = write & execute
  • 6 = 2+4 = read & write
  • 7 = 1+2+4 = read & write & execute

First number applies for owner(user), second for group, and the last for others. So, the command below means full permission for user, write & execute permission for group and others.

chmod 755 FILE

Also add -R for folder and all sub-files/folder. For example, grant read & write for user(owner) but no permission for all others.

chmod 600 -R FOLDER

There are lots of tutorials about this stuff in the web, and I got one here: https://fostips.com/tell-change-file-permission-owner-linux/

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.