Differences between chown and chmod?

Differences between chown and chmod?

Nutshell

The chmod and chown commands are used to control access to files in UNIX and Linux systems.

The chmod command stands for "change mode", and allows changing permissions of files and folders, also known as "modes" in UNIX.

The chown command stands for "change owner", and allows changing the owner of a given file or folder, which can be a user and a group.

chmod

The chmod command can be used in a couple of different ways, with permissions (or modes) set by numbers or by letters.

by numbers

4 = read

2 = write

1 = execute

To set this mode with chmod on a file called important.txt we would simply run this command:

chmod 644 important.txt

First position (in the above example 6) refers to the user.

Second refers to the group of the user.

Third refers to all others.

by letters

u = user

g = group

o = others

a = all users

r = read

w = write

x = execute

+ = add permission

- = remote permission

For example, to accomplish the 644 permissions above we would run this:

chmod u+rw,go+r important.txt

So we're saying file owner user gets read and write permissions, group and others get to read.

If important.sh already had permissions set to 644 we can add everyone execute rights by simply running:

chmod +x important.sh

Finally, if we're setting permissions to a folder we need to specify the -R option (standing for "recursive"):

chmod -R 644 important-files/

chown

Basic usage of chown is pretty straightforward. You just need to remember that first comes the user (owner), and then the group, delimited by a colon.

This command will set the user "daniel", from the group of "admins" as owners of the directory "important-files":

chown -R daniel:admins important-files

Just like with chmod, the -R is there when it's a directory.

results for ""

    No results matching ""