command: chmod

Rob

Administrator
Staff member
Credits
36
chmod is a Linux command that will let you "set permissions" (aka, assign who can read/write/execute) on a file.

Usage:
Code:
 chmod permissions file
OR:
Usage:
Code:
 chmod permission1_permission2_permission3 file
When using chmod, you need to be aware that there are three types of Linux users that you are setting permissions for. Therefore, when setting permissions, you are assigning them for "yourself", "your group" and "everyone else" in the world. These users are technically know as:

● Owner
● Group
● World
Therefore, when setting permissions on a file, you will want to assign all three levels of permissions, and not just one user.

Think of the chmod command actually having the following syntax...
chmod owner group world FileName
Now that you understand that you are setting permissions for THREE user levels, you just have to wrap your head around what permissions you are able to set!

There are three types of permissions that Linux allows for each file.

● read
● write
● execute
Putting it all together:
So, in laymen terms, if you wanted a file to be readable by everyone, and writable by only you, you would write the chmod command with the following structure.
COMMAND : OWNER : GROUP : WORLD : PATH
chmod read & write read read FileName
chmod 6 4 4 myDoc.txt
Wait! What are those numbers?!?
Computers like numbers, not words. Sorry. You will have to deal with it. Take a look at the following output of `ls -l`
Code:
[[email protected]]$ ls -l 
-rw-r--r-- 1 gcawood iqnection 382 Dec 19 6:49 myDoc.txt
You will need to convert the word read or write or execute into the numeric equivalent (octal) based on the table below.

● 4 – read (r)
● 2 – write (w)
● 1 – execute (x)
Practical Examples

chmod 400 mydoc.txt – read by owner
chmod 040 mydoc.txt – read by group
chmod 004 mydoc.txt – read by anybody (other)
chmod 200 mydoc.txt – write by owner
chmod 020 mydoc.txt – write by group
chmod 002 mydoc.txt – write by anybody
chmod 100 mydoc.txt – execute by owner
chmod 010 mydoc.txt – execute by group
chmod 001 mydoc.txt – execute by anybody
Wait! I don't get it... there aren't enough permissions to do what I want!
Good call. You need to add up the numbers to get other types of permissions...

So, try wrapping your head around this!!
7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)

chmod 666 mydoc.txt – read/write by anybody! (the devil loves this one!)
chmod 755 mydoc.txt – rwx for owner, rx for group and rx for the world
chmod 777 mydoc.txt – read, write, execute for all! (may not be the best plan in the world...)
Good luck! Hope this helps.
(ps, never set things to 777 unless you have a really good reason to do so.)
 


StarBaseONE2

New Member
Credits
0
This one took me a while to understand well enough to be able to use without having to 'argue' with my machine to achieve the results I desired. LOL

Rob this was a good way of presenting the concept.
 

kenux

New Member
Credits
0
chmod is a Linux command that will let you "set permissions" (aka, assign who can read/write/execute) on a file.

Usage:
Code:
 chmod permissions file
OR:
Usage:
Code:
 chmod permission1_permission2_permission3 file
When using chmod, you need to be aware that there are three types of Linux users that you are setting permissions for. Therefore, when setting permissions, you are assigning them for "yourself", "your group" and "everyone else" in the world. These users are technically know as:



Therefore, when setting permissions on a file, you will want to assign all three levels of permissions, and not just one user.

Think of the chmod command actually having the following syntax...


Now that you understand that you are setting permissions for THREE user levels, you just have to wrap your head around what permissions you are able to set!

There are three types of permissions that Linux allows for each file.



Putting it all together:
So, in laymen terms, if you wanted a file to be readable by everyone, and writable by only you, you would write the chmod command with the following structure.


Wait! What are those numbers?!?
Computers like numbers, not words. Sorry. You will have to deal with it. Take a look at the following output of `ls -l`
Code:
[[email protected]]$ ls -l
-rw-r--r-- 1 gcawood iqnection 382 Dec 19 6:49 myDoc.txt
You will need to convert the word read or write or execute into the numeric equivalent (octal) based on the table below.



Practical Examples



Wait! I don't get it... there aren't enough permissions to do what I want!

Good call. You need to add up the numbers to get other types of permissions...

So, try wrapping your head around this!!
7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)



Good luck! Hope this helps.
(ps, never set things to 777 unless you have a really good reason to do so.)
0=7-7-7
 

mudz

New Member
Credits
0
One question?
Suppose I've mounted one drive which is also shared by windows file system. Now if I change permissions to one of that file will it have any affect on that file when I use windows? or chmod is only isolated to linux system? Dumb question it is?
o_O
 

Chainzaw

New Member
Credits
0
One question?
Suppose I've mounted one drive which is also shared by windows file system. Now if I change permissions to one of that file will it have any affect on that file when I use windows? or chmod is only isolated to linux system? Dumb question it is?
o_O
Mudz,

It's been a very long time since I ran a dual system, but Windoze system generally give full access as if root under linux, so all should be fine.

But, a simple test can be performed.

In M$ you can create a test document and/or folder with test files copied or filled with gibberish, boot to Linux and disallow all priveledges, then see if the folder and/or files can be modified and saved in the Windows environment.

As stated, I've not run much of any computers in some time, but in my recollection..

Chmod 000 testfile.txt

should remove all permissions.

@kenux shows 0=777 and that may be correct.

I'll have to get back into things.
 

Neelgt

New Member
Credits
0
Hey..
I am using linux for the first time.When i using chmod commnad and give the permission to write in the group it accept that but when i undo that command from write to read mode using 'g-w' it shows "bash: g-w : commnad not found.

It also show when i was using info command for getting infomation of any command.
Pls resolve my issue......
I'm using deepin...
 

igor-ignat

Gold Member
Gold Supporter
Credits
0
chmod is a Linux command that will let you "set permissions" (aka, assign who can read/write/execute) on a file.

Usage:
Code:
 chmod permissions file
OR:
Usage:
Code:
 chmod permission1_permission2_permission3 file
When using chmod, you need to be aware that there are three types of Linux users that you are setting permissions for. Therefore, when setting permissions, you are assigning them for "yourself", "your group" and "everyone else" in the world. These users are technically know as:



Therefore, when setting permissions on a file, you will want to assign all three levels of permissions, and not just one user.

Think of the chmod command actually having the following syntax...


Now that you understand that you are setting permissions for THREE user levels, you just have to wrap your head around what permissions you are able to set!

There are three types of permissions that Linux allows for each file.



Putting it all together:
So, in laymen terms, if you wanted a file to be readable by everyone, and writable by only you, you would write the chmod command with the following structure.


Wait! What are those numbers?!?
Computers like numbers, not words. Sorry. You will have to deal with it. Take a look at the following output of `ls -l`
Code:
[[email protected]]$ ls -l
-rw-r--r-- 1 gcawood iqnection 382 Dec 19 6:49 myDoc.txt
You will need to convert the word read or write or execute into the numeric equivalent (octal) based on the table below.



Practical Examples



Wait! I don't get it... there aren't enough permissions to do what I want!

Good call. You need to add up the numbers to get other types of permissions...

So, try wrapping your head around this!!
7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)



Good luck! Hope this helps.
(ps, never set things to 777 unless you have a really good reason to do so.)
thank you. hope to study more efficiently with your book.
 
  • Like
Reactions: Rob

Rob

Administrator
Staff member
Credits
36
Hey..
I am using linux for the first time.When i using chmod commnad and give the permission to write in the group it accept that but when i undo that command from write to read mode using 'g-w' it shows "bash: g-w : commnad not found.

It also show when i was using info command for getting infomation of any command.
Pls resolve my issue......
I'm using deepin...
Sorry for the late reply - i'm thinking you're not putting 'chmod' before the g-w part.. did you get this sorted out?
 

captain-sensible

Well-Known Member
Credits
2,158
chmod is a Linux command that will let you "set permissions" (aka, assign who can read/write/execute) on a file.

Usage:
Code:
 chmod permissions file
OR:
Usage:
Code:
 chmod permission1_permission2_permission3 file
When using chmod, you need to be aware that there are three types of Linux users that you are setting permissions for. Therefore, when setting permissions, you are assigning them for "yourself", "your group" and "everyone else" in the world. These users are technically know as:



Therefore, when setting permissions on a file, you will want to assign all three levels of permissions, and not just one user.

Think of the chmod command actually having the following syntax...


Now that you understand that you are setting permissions for THREE user levels, you just have to wrap your head around what permissions you are able to set!

There are three types of permissions that Linux allows for each file.



Putting it all together:
So, in laymen terms, if you wanted a file to be readable by everyone, and writable by only you, you would write the chmod command with the following structure.


Wait! What are those numbers?!?
Computers like numbers, not words. Sorry. You will have to deal with it. Take a look at the following output of `ls -l`
Code:
[[email protected]]$ ls -l 
-rw-r--r-- 1 gcawood iqnection 382 Dec 19 6:49 myDoc.txt
You will need to convert the word read or write or execute into the numeric equivalent (octal) based on the table below.



Practical Examples



Wait! I don't get it... there aren't enough permissions to do what I want!
Good call. You need to add up the numbers to get other types of permissions...

So, try wrapping your head around this!!
7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)



Good luck! Hope this helps.
(ps, never set things to 777 unless you have a really good reason to do so.)
here is something that i will throw in 755 is used (it seems ) as standard chmod for directories on a server and chmod 644 for files.

Why is that ?

Also here is an example of chmod(used in a slackbuild) with find :
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

My understanding of the above is that we are using find with -L flag which follows symbolic links, perm flag uses permissions and what i think it does is change all directories to chmod 775 and all files to 644. Anyone like to throw in their thoughts?
 
D

Deleted member 92873

Guest
I look something the book for the beginner Linux tutorial book online for free I unable to find the right information to learn how to do with a command with thru command prompt.
 

Soulful_Quaser

New Member
Credits
0
Probably a stupid question, (I am full of them o_O) Trying to understand the difference between the permissions:-

Read = Read only can't edit
Write = Can edit i.e can modify a document
Execute = ???

I don't get, if i can read/write a program surely i could run it? Obviously the answer must be no, otherwise there wouldn't be an execute permission :p. But then does that mean if i had read and write access does that also give me the ability to completely change or screw up a program, just not allowed to run it?

Could someone give me a simple example of a program or document using all three permissions?

Thanks for your help :)
 

captain-sensible

Well-Known Member
Credits
2,158
putting it simply reading a file allows to read say a document; write permissions allow you to write i.e edit the document. But a document say something.txt is a text file an not a program. IN windows you have .exe which are "executable programs" .

So the "execute" permissions are to do with running a program.

So lets take a simple example.

lets write a mini bash script.
#!/bin/bash

echo hello world

save the above two lines as helloworld to Desktop


if i go to go to desktop
cd Desktop
//note captial letter

and type ls -l i get :

-rw-r--r-- 1 andrew users 30 Jan 18 13:50 helloworld

it shows because i'm logged into my linux as "user" and i created a file i have default permissions; these are read write but not execute if i try to "run" this script i get permission denied .

if i am on Desktop i can run it as follows:

./helloworld

to give me execute permissions i do :

chmod 755 helloworld. Nopw when i run it it outputs " hello world"
 

captain-sensible

Well-Known Member
Credits
2,158
there are finer points with webs etc in permissions needed by a program to enter or do anything to a directory, thus the common permissions for directories on a Linux server are 755 and files 644
 


Members online


Latest posts

Top