Change owner, group and permissions (Linux)

Change owner/group

chown [options] [owner][:[group]] file

Examples

chown root file.txt        // For file.txt set owner to root
chown -R root:admin folder // For folder (+ items) set owner to root & group to admin

Change permissions

chmod [options] mode file

Mode
– Symbolic

[category][operator][permissions]

- category
    u ... user
    g ... group
    o ... other

- operator
    = ... set
    + ... add
    - ... remove

- permission
    r ... read
    w ... write
    x ... execute

– Numeric

[octal][octal][octal]
   ↑      ↑      ↑
  User  Group  Other

- Octal
    Bit_0 Bit_1 Bit_2
      ↑     ↑     ↑
      x     w     r

Examples

chmod 777 file.txt       // For file.txt set perm. rwx to user, group & other
chmod -R o+r folder      // For folder (+ sub items) add perm. r to other
chmod u=rw,g=rw file.txt // For file.txt set perm. rw to user & group
chmod +x script.sh       // For script.sh add perm. x to user, group & other

Caution: To remove a file/directory you need write permission on the parent directory.