The chmod and chown commands in Linux are used to change the permissions and ownership of files and directories. Here’s a simple guide with examples:

chmod Command:

The chmod command is used to change the permissions of a file or directory.

Syntax:

chmod [options] permissions file

Options:

+ : Adds the specified permissions.

- : Removes the specified permissions.

= : Sets the specified permissions and removes all others.

Permissions:

r : Read

w : Write

x : Execute

Examples:

  1. Give read, write, and execute permissions to the owner of a file:

chmod u+rwx filename

  1. Remove write permissions from the group of a file:

chmod g-w filename

  1. Add execute permissions to others (everyone else) for a directory:

chmod o+x directoryname

  1. Set read and write permissions for the owner, and read-only permissions for the group and others:

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

chown Command:

The chown command is used to change the owner and/or group of a file or directory.

Syntax:

chown [options] user:group file

Options:

-R : Recursively chan0ge ownership of directories and their contents.

Examples:

  1. Change the owner of a file to a specific user:

chown username filename

  1. Change the owner and group of a file:

chown username:groupname filename

  1. Recursively change the owner and group of a directory and its contents:

chown -R username:groupname directoryname

Additional Tips:

You can combine chmod and chown in a single command by separating them with ;. For example:

chmod u+r filename; chown username:groupname filename

Make sure to use these commands carefully, as incorrect usage can lead to security issues.

These are basic examples to get you started with chmod and chown. You can refer to the respective man pages (man chmod and man chown) for more details and options.