To assign read, write and execute permissions to the owner, and read permissions only to the group and other users, run the command: $ chmod 744 devops.txt Therefore, we arrive at the value of 754 as the numeric value for the file permissions of the given file. Let’s assume the owner has read, write and execute permissions, the group has read and execute permissions and other users have read permissions only, this can be broken down as follows: read, write and execute in each of the three segments account for the complete permissions of a given file or directory. The total sum of the values of the permissions i.e. The read, write and execute permissions take the following values: However, in most cases, 3 numbers are used. The numeric value can take 3 or 4 numbers. When setting permissions using the numeric style/notation, use the syntax shown below: Example 1) Assign permissions using numeric notation Let’s now delve and see different examples of chmod command. You can pass more than one file or directory separated by spaces in the command syntax. Only the root user or a regular user with sudo privileges can change file or directory permissions. The chmod command in Linux is used to change file and directory permissions using either text (symbolic) or numeric (octal) notation.
#Chmod examples 777 how to
Having looked at the file permissions and how to view them, let’s no focus on how to modify these permissions. Using chmod command to set file & directory permissions The triple hyphen symbols - indicate no permissions have been granted for either the owner of the file, group or other users. We can see that the owner of the directory and group has all the permissions (read, write and execute) while other users have read and execute permissions only. Let’s look at the directory’s permissions: drwxrwxr-x 2 linuxtechi linuxtechi 4096 Aug 17 15:43 sales The same permissions also apply for the reports.zip compressed file. Let’s examine the first file -rw-rw-r- 1 linuxtechi linuxtechi 35 Aug 17 15:42 hello.txtįor the first file, the -rw-rw-r– permissions imply that the owner of the file has read and write permissions, the group also bears read & write permissions, while other users only have read permissions. As pointed out earlier, the first segment points to the owner permissions, the second indicates the group permissions and the last portion specifies the permissions that other users have on the file or directory.įrom the output, we can see that we have 2 files (hello.txt & reports.zip) and a single directory. The remaining nine characters are segmented into 3 triplets each bearing three symbols r(read), w(write) and x(execute). Symbol l indicates that it’s a symbolic link. The symbol d indicates that it is a directory. A hyphen (-) indicates that the file is a regular file. Starting from the extreme left, the first character/symbol indicates the file type. To get a better understanding of file permissions, we are going to list the contents of our directory as shown: $ ls -l The permissions are arranged in three sets: the user, group and others respectively You can assign these permissions using the text or octal (numeric) notation as we shall later discuss in this tutorial.įiles and directories can belong to either the owner of the file (u), group (g) or others (o)įile permissions are listed using the ls -l command. These permissions determine which users can read, write or execute the files. In Linux, we have 3 types of file permissions: read (r), write (w) and execute (x) permissions.