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
 

Staff online

Members online


Top