How to change permissions?

You can change file and directory permissions in Linux using the chmod command. Here are the common methods to do so:

1. Using Symbolic Notation:

You can specify permissions using letters:

  • u: User (owner)
  • g: Group
  • o: Others
  • a: All (user, group, and others)

You can add (+), remove (-), or set (=) permissions.

Examples:

  • To add execute permission for the owner:

    chmod u+x filename
    
  • To remove write permission for the group:

    chmod g-w filename
    
  • To set read and write permissions for the owner and remove all permissions for others:

    chmod u=rw, o= filename
    

2. Using Numeric (Octal) Notation:

Permissions can also be set using numbers, where:

  • 4: Read
  • 2: Write
  • 1: Execute

You combine these numbers for each user category (owner, group, others).

Examples:

  • To set permissions to rwxr-xr-- (755):

    chmod 755 filename
    
  • To set permissions to rw-r----- (640):

    chmod 640 filename
    

3. Recursively Changing Permissions:

To change permissions for a directory and all its contents, use the -R option:

chmod -R 755 directory_name

This command sets the permissions for the directory and all files and subdirectories within it.

If you have any further questions or need more examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!