Cheat Sheet #day71 - chown

Cheat Sheet #day71 - chown

chown Command Cheatsheet

The chown command in Unix-like systems is used to change the ownership of files and directories. It allows users to transfer ownership from one user to another and optionally change the group ownership as well. Here’s a quick reference guide:

Basic Syntax

chown [OPTIONS] OWNER[:GROUP] FILE...

Common Options

  • -c, --changes: Report only when a change is made.

      chown -c user1:group1 file.txt
    
  • -v, --verbose: Output a diagnostic for every file processed.

      chown -v user2:group2 file.txt
    
  • -R, --recursive: Recursively change ownership of directories and their contents.

      chown -R user3:group3 directory/
    

Ownership Syntax

  • OWNER: Specifies the new owner of the file or directory.

  • GROUP: Optionally specifies the new group for the file or directory. If omitted, the group remains unchanged.

Examples

  1. Change ownership of a file:

     chown user1 file.txt
    
  2. Change ownership and group of a file:

     chown user2:group2 file.txt
    
  3. Change ownership recursively for a directory and its contents:

     chown -R user3:group3 directory/
    
  4. Verbose mode (display actions performed):

     chown -v user4:group4 file.txt
    

Additional Information

  • Help option:

      chown --help
    
  • View manual page for chown:

      man chown
    

The chown command is essential for managing file and directory ownership in Unix-like systems. It allows administrators and users to control access and permissions by assigning ownership to specific users and groups. For more detailed options and usage scenarios, refer to the man page or use chown --help.

Did you find this article valuable?

Support Cloud Tuned by becoming a sponsor. Any amount is appreciated!