command: chmod

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"

Thanks Capitaine, I will have a little practice of that when i get home. :)
 


I use mini tool to check how much something partition in my disk then there is 10 partition of the disk on it. and look like I have to buy new disk or could fix that swipe whole of partition away from disk? I still use 10 window on laptop , look more information to get how work nor have to get new disk .. I have 256 GB ( sandisk ) Linux might able install on new sandisk , is it enough for Linux mint to boot ?
 
I use mini tool to check how much something partition in my disk then there is 10 partition of the disk on it. and look like I have to buy new disk or could fix that swipe whole of partition away from disk? I still use 10 window on laptop , look more information to get how work nor have to get new disk .. I have 256 GB ( sandisk ) Linux might able install on new sandisk , is it enough for Linux mint to boot ?

More than enough. I'm running MX Linux on a 32-gig USB stick, with room to spare.
 
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:
[root@demo]$ 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.)
Rob, outstanding again, cheers mate ;-)
 
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:
[root@demo]$ 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.)
I love this command
 
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:
[root@demo]$ 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.)
can someone help with explaining "chmod +x ./filename.sh"
 
can someone help with explaining "chmod +x ./filename.sh"

You're adding the 'executable bit', meaning that the file has permissions to run as an executable - something that can be executed like a program. You can still open it with other things, with varied degrees of success, but now you can execute the file.

The main permissions are read, write, and execute. You're enabling the latter.
 
You're adding the 'executable bit', meaning that the file has permissions to run as an executable - something that can be executed like a program. You can still open it with other things, with varied degrees of success, but now you can execute the file.

The main permissions are read, write, and execute. You're enabling the latter.
is there another way of using the chmod command to make that shell file example an executable?
 
is there another way of using the chmod command to make that shell file example an executable?

There's probably some convoluted method that you shouldn't need. I mean, you can make it complicated with some sort of find command, but that's not going to change anything.

Is the command not working, or something like that?

You can also (probably) use your GUI file manager. Just look for 'permissions' or the like and set the executable bit.
 
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

Yeah, Microsoft is still studying on the concept of file ownership, but one day ...

Compared to Unix/Linux, the Windows file ownership system is still in pre-alpha state. If a file cannot be accessed, NOBODY knows why.
 
Really helpful. Thanks.

Edit: is the explanation for "Owner/Group/World" terms gonna come later?

So, basically, Linux/Unix is written by ... well, lets say people with a specific mind-set.
All is logic, but sometimes the logic is not clear at first.

"World" just means : for everybody. As in : everybody in the world.
"Group" then just refers to the Unix/Linux ownership which operations on a 2 level system: users are owners, but users can be put in a group. Each owner/user must have 1 primary group and can be part of multiple other groups. As a result, a Group can exist out of zero, 1 or more users. And there are special groups but what I stated is for normal groups.
 
I am fiddling around with permissions and chmod - and just on my own linux box

I tend to make the scripts chmod 744 (rwxr--r--) so only i can run but any can read ( and not write or execute )

PS -- the chmod +x sets the "x" or the "1" bit
note they would all become "odd" to get 755 in my case above
 
Last edited:
I'm relatively new to linux and honestly this mini cheatsheet made it way easier for me to understand.

Hope this can help someone else like it did me.
chmod examples.png
 
I'm relatively new to linux and honestly this mini cheatsheet made it way easier for me to understand.

Hope this can help someone else like it did me.
View attachment 21618
That's a really nice cheat sheet, and small enough to keep around on a little card or whatever but if I might make a couple of suggestions:

1) think of "owner" as "user" (even though "owner" seems like a more accurate word in this context. Maybe think, "user who owns it". :) ) - for two reasons. First, it doesn't begin with 'o' so avoids confusion with "others" and second, chmod actually "understands" the term "user" (a la the use of 'u' in the following suggestion...

2) instead of using the octal codes, even though that's perfectly legit, you can refer to "user", "group" and "others" as 'u', 'g' and 'o' and use a syntax like this:
Code:
chmod u+x myfile
gives the owner ("user") execute permission independently of the owner's read and write permissions and independently of the group's and others' read, write and execute permissions. For those of us who don't do this sort of thing in our sleep, this also removes the need for remembering the order of user, group and others and the order of the read, write and execute bits. All of the expected combinations of user, group and others permissions for read, write and execute will work this way and can be combined such that. for instance,
Code:
chmod ugo+rwx myfile
is exactly equivalent to
Code:
chmod 777 myfile
And, of course, one can use the minus sign to take away certain permissions:
Code:
chmod go-w myfile
 
I'm relatively new to linux and honestly this mini cheatsheet made it way easier for me to understand.

Hope this can help someone else like it did me.
View attachment 21618

I just still calculate
4 is Read
2 is Write
1 is eXecute

For the owner (and talking about FILES, not directories), you'd almost always want Read, which is 4
and then there's 3 options
  • with Write only is 6 (typical for non-executable files)
  • with eXecute and Write is 7 (typical for executable files)
  • with eXecute only (with is an uncommon combo for owner) is 5

Of course Read only (for owner) is possible but I don't see many files with that. It's a Read only file system if all of your files have that. And group and other have even less, so nothing probably.
And even more weird is zero for owner, but it is possible.

Group and others can have anything really, but never more, so no
557
or
667



And for DIRECTORIES, well, that is different :)
 
Last edited:
I just still calculate
4 is Read
2 is Write
1 is eXecute

For the owner (and talking about FILES, not directories), you'd almost always want Read, which is 4
and then there's 3 options
  • with Write only is 6 (typical for non-executable files)
  • with eXecute and Write is 7 (typical for executable files)
  • with eXecute only (with is an uncommon combo for owner) is 5

Of course Read only (for owner) is possible but I don't see many files with that. It's a Read only file system if all of your files have that. And group and other have even less, so nothing probably.
And even more weird is zero for owner, but it is possible.

Group and others can have anything really, but never more, so no
557
or
667



And for DIRECTORIES, well, that is different :)
this is perfectly said .. many combinations are possible but in practice , we use very few in basic file permissions
744 -- i tend to use this at home rather than 777 , i dont really know why , feels right
777
766
 
I just still calculate
4 is Read
2 is Write
1 is eXecute

For the owner (and talking about FILES, not directories), you'd almost always want Read, which is 4
and then there's 3 options
  • with Write only is 6 (typical for non-executable files)
  • with eXecute and Write is 7 (typical for executable files)
  • with eXecute only (with is an uncommon combo for owner) is 5

Of course Read only (for owner) is possible but I don't see many files with that. It's a Read only file system if all of your files have that. And group and other have even less, so nothing probably.
And even more weird is zero for owner, but it is possible.

Group and others can have anything really, but never more, so no
557
or
667



And for DIRECTORIES, well, that is different :)
That’s actually really helpful information. Had no idea you could calculate it.

Thank you for the in depth explanation!
 
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.
Also a-rwx filename would remove all permissions
 


Top