Chmod in Ubuntu
What is chmod
chmod: Change the mode of each FILE to MODE.
Let's know something about the linux file permission
ls -l
the first column will show the permissions for
files.
1 | ls -l |
On each line, the first character identifies the type of entry that
is being listed.If it is a dash(-), it is a file. If is the letter
d
, it is a directory.
The next 9 characters represent the settings for
user permissions
, group permissions
and
other permission
(each 3 characters).
User
is the one who owns the file. Group
is
the other users in the group(add the link to another article here).
Other
can be anyone not in the first two categories.
There are 3 characters in each set of permission. The character means:
-
: Permission not granted.r
: Read permission. The file can be opened and its content viewed.w
: Write permission. Th filed can be edited, modified and delted.x
: Execute permissions. If the file is a script or a program (like a shell script), it can be executed.
Let's see an example.
drwxr-xr-x 3 liwuchen staff 96 Jul 15 22:05 PaperSharing
PaperSharing is a directory. User
(`Liwuchen
) can write, read and execute (for directory, it
means cd
). Goup
(Staff
) can read
and execute it. Other
can read and execute it too. The size
of this directory is 96 bytes. The directory is created at 22:05 15
Jul.
How to use chmod
The syntax for chmod
is:
chmod <who><what><which> <file name>
(put it to a table here)
<who>
:
u
: user, the owner of the fileg
: group, members of the group the file belongs too
: othersa
: all above, anyone If you do not specify<who>
,chmod
will takea
as default.
<what>
:
-
: remove permission+
: add permission=
: set a permission and remove others
<which>
:
r
: read permissionw
: write permissionx
: execute permission
eg. chmod u=rwx, og=r file.txt
chmod +x scipt.sh
chmod o-r *.txt
Numerical Shorthand
- 0: no permission
- 1: execute
- 2: write
- 3: write & execute
- 4: read
- 5: read & execute
- 6: read & write
- 7: read & write & execute
CLICK HERE for more information.