In Unix-like operating systems, the chmod command is used to change the access mode of a file.
The name is an abbreviation of change mode.
Syntax :
The references are used to distinguish the users to whom the permissions apply i.e. they are list of letters that specifies whom to give permissions. The references are represented by one or more of the following letters:
The operator is used to specify how the modes of a file should be adjusted. The following operators are accepted:
Hi everyone I was trying to open a file (a keygen to be more precise).it was non-executable so I used chmod +x command in terminal and everything went. Chmod +x myscript.py. And execute it like this:./myscript.py Using the Python shell. You can open a Python shell simply by typing python or python3 into a Terminal window. Then you can run Python commands directly in the shell. Python one-liners. You can also execute Python directly on the cli using the -c option.
Note : Putting blank space(s) around operator would make the command fail.
The modes indicate which permissions are to be granted or removed from the specified classes. There are three basic modes which correspond to the basic permissions:
Types of permissions which we will be changing using chmod command :
In linux terminal, to see all the permissions to different files, type ls -l command which lists the files in the working directory in long format. The figure below shows an example to use ls -l and its output :
Let us take a look at above figure. To make things easy to understand some columns and rows are eliminated and extra spaces are added to the permissions column to make it easier to read as shown below:
- The very first column represents the type of the file i.e. is it a normal file or a
directory where d represents a directory and – represents a normal file. - The first set three letters after the file type tell what the Owner of the file, have permissions to do. For example: In assgn1_client.c, has owner’s permission as rw-, which means the owner mik can only read(r) and write(w) the file but cannot execute(x).
- Note: The 3rd and 4th columns represents the name of the owner of the file and the group to which the owner belongs respectively.
- The next three letters after the user’s permission are the group’s permissions.
For example: header.sh has group permissions as r-x, which means Other people in the mik group can not write(w) the header.sh script but can only read(r) or execute(x) it. - Note that when a directory has the x set, this takes the special meaning of “permitted to search this directory”.
- The last three letters in the permissions column tell us what the “others” may do. The general practice is to protect the files from external access so that others can’t write any files or directories. They may read(r) or execute(x) it. For example: The assgn1_client.c has others permission as r- – which means it can only be read by other(external) access but cannot be written or executed by them.
How To Chmod A File
Now, let us see how chmod command can be used to change the access mode of a file.
Example 1 :
Let’s change the assgn1_client.c permission so that the owner cannot write(w) in the file but can only read it.
Before :
After :
Example 2 :
Let’s restrict the permission such that the user cannot search the directory EXAM.
After applying the chmod u=rw EXAM command, the user (owner) cannot change the directory. If the user tries to change the directory, then it shows the message “Permission denied” as shown in the figure below :
Reference :
chmod Wikipedia
Recommended Posts:
Open A Terminal Chmod X Keygen_osx 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the 'Improve Article' button below.