Using Chmod Command to Change File or Directory Permissions

Syntax:
The syntax is
chmod [options] [MODE] filename

File Permissions

# File Permissions
0 No Permissions
1 Execute Permission Only
2 Write Permission Only
3 Execute and Write Permissions
4 Read Permission Only
5 Read and Execute Permissions
6 Read and Write Permissions
7 All Permissions

Command Options:

-c Only show the names of files whose permissions have changed.
-f Suppress most error messages.
-R Recursively change permissions for files and subdirectories.
-v Output version information and exit.

Examples:
View your files, regardless of their permissions:
ls -alt

  1. Use this command to view your files regardless of their permissions.
  2. Grant read and write permissions to the group and other users.
    chmod 066 file1.txt
  3. Allow all users to have read, write, and execute permissions.
    chmod 777 file1.txt

chgrp Command

The chgrp command is used to change the group ownership of a file or directory. This is an administrator command. Only administrator users can change the group ownership of files or directories.

Syntax:
The syntax is
chgrp [options] newgroup filename/directoryname

Command Options:

-R Change the permissions of files in the subdirectories of your current directory.
-c Change the permissions for each file.
-f Forceful. Does not report errors.

Examples:

  1. chgrp hiox test.txt
    This ‘test.txt’ file group is the admin group, changed to the new group hiox.
  2. chgrp -R hiox test
    This ‘test’ directory group is the root directory. Using the -R option, files and their subdirectories are changed to the new group hiox.
  3. chgrp -c hiox calc.txt
    The above command is only used to change the group of the specified file (‘calc.txt’).

Leave a Comment