What is chmod?
chmod is a Terminal command in Linux Operating systems, chmod stands for "change mode", The chmod command is used to change permissions of a file. This chmod command is available for Linux Operating systems and as we know Android is also based on Linux and It supports almost all basic Linux commands, so let's check it out how can we use chmod in Android shell through ADB.
There are three mode of permissions that can be applied to a file
- ro (Read Only)
- rw (Read-Write)
- rwx (Read-Write-execute)
If the file has permission "ro" then user can read the file only, User cannot edit or write in the file, and also cannot execute that file as a program.
If the file has permission "rw" then user can read the file and also write in the file, But user cannot execute the file.
If the file has permission "rwx" then user can read the file write in the file and can execute the file as a programs.
Example - An user has create a .bin file by compiling a program in C language, and it has permissions "rw" i.e. read-write, User can edit or modify that file but cannot run the file because file does not have permissions to execute, Here chmod can be used to make file executable by changing permissions of that file.
How chmod works in adb terminal?
Before proceeding to chmod we need to understand basic concept of binary numbers.
The binary number are 0 and 1. The 0 represents False and 1 represents True.
We will see binary numbers in 3 digit i.e. 3 bit binary
In above table First row shows decimal numbers and as well as modes of permissions r represents Read, w represents Write, x represents Execute.
Example - Consider above table, If user wants to change permissions of a file as read-write(rw) and don't want to execute that file, then user can mark "r" and "w" as true i.e 1,1 and "x" as false i.e. 0 , its binary will be 110 and check its Decimal number it is 6.
There is multiple users in android, First the system itself is a user, and second is a normal (Human) user that will use the device and third is other things like downloaded applications,etc
In above table there are three users,
now consider 3rd row we want to change permissions of a file as read only for all users therefore we consider all binary as 100, which has output 444.
in 4th row we want to allow execution of a file for system and user and do not want to execute file for others like third party applications therefore we have given binary 111 for system and user and 100 for others.
After understanding the binary numbers we can proceed to chmod command
Syntax - chmod < decimal numbers for system-user-other> <file name>
Example - An user wants to change permissions of a file named as a.sh, and want it executable for all users then the command will be as follows.
Comments
Post a Comment