@@ -21,21 +21,25 @@ The `chmod` (change mode) command is used to change the permissions of a file or
21
21
### File Permission Structure
22
22
23
23
Each file has three sets of permissions:
24
+
24
25
1 . ** Owner (u)** : The user who owns the file.
25
26
2 . ** Group (g)** : The group that owns the file.
26
27
3 . ** Others (o)** : All other users.
27
28
28
29
Each set has three permission types:
30
+
29
31
- ** Read (r)** : Permission to read the file.
30
32
- ** Write (w)** : Permission to modify the file.
31
33
- ** Execute (x)** : Permission to execute the file as a program.
32
34
33
35
#### Example
34
36
35
- ```
37
+ ``` plain-text
36
38
-rw-r--r--
37
39
```
40
+
38
41
This representation indicates:
42
+
39
43
- ` r ` and ` w ` for the owner (read and write permissions)
40
44
- ` r ` for the group (read permission)
41
45
- ` r ` for others (read permission)
@@ -54,25 +58,34 @@ chmod ugo=rwx file.txt # Set all permissions for everyone
54
58
```
55
59
56
60
#### Numeric Method
61
+
57
62
Permissions can also be represented using octal numbers:
63
+
58
64
- ` r ` = 4, ` w ` = 2, ` x ` = 1
59
65
- Add them together for each set.
60
66
61
67
Example:
68
+
62
69
``` bash
63
70
chmod 755 file.txt
64
71
```
72
+
65
73
In this case:
74
+
66
75
- Owner: 7 = rwx
67
76
- Group: 5 = r-x
68
77
- Others: 5 = r-x
69
78
70
79
** Examples** :
80
+
71
81
- Grant full permissions to the owner, and read-only to others:
82
+
72
83
``` bash
73
84
chmod 744 file.txt
74
85
```
86
+
75
87
- Make a script executable for everyone:
88
+
76
89
``` bash
77
90
chmod +x script.sh
78
91
```
@@ -84,45 +97,60 @@ The `chown` (change owner) command is used to change the ownership of a file or
84
97
### Ownership Structure
85
98
86
99
Each file or directory has:
100
+
87
101
1 . ** Owner** : The user who owns the file.
88
102
2 . ** Group** : The group associated with the file.
89
103
90
104
### Basic Usage of ` chown `
91
105
92
106
#### Change Owner
107
+
93
108
To change the owner of a file:
109
+
94
110
``` bash
95
111
chown new_owner file.txt
96
112
```
97
113
98
114
#### Change Group
115
+
99
116
To change the group associated with a file:
117
+
100
118
``` bash
101
119
chown :new_group file.txt
102
120
```
103
121
104
122
#### Change Both
123
+
105
124
To change both the owner and group:
125
+
106
126
``` bash
107
127
chown new_owner:new_group file.txt
108
128
```
109
129
110
130
#### Recursive Ownership Change
131
+
111
132
To apply changes to a directory and all its contents:
133
+
112
134
``` bash
113
135
chown -R new_owner:new_group directory_name
114
136
```
115
137
116
138
** Examples** :
139
+
117
140
- Make ` john ` the owner of ` file.txt ` :
141
+
118
142
``` bash
119
143
chown john file.txt
120
144
```
145
+
121
146
- Change the group to ` developers ` :
147
+
122
148
``` bash
123
149
chown :developers file.txt
124
150
```
151
+
125
152
- Make ` john ` the owner and ` developers ` the group of a directory and its contents:
153
+
126
154
``` bash
127
155
chown -R john:developers /project
128
156
```
@@ -143,19 +171,24 @@ In Unix/Linux commands, options can be specified in two ways: short (`-`) and lo
143
171
| ` - ` | Short options (single-letter) | ` chmod -R 755 directory ` (recursive) |
144
172
| ` -- ` | Long options (full-word) | ` chmod --recursive 755 directory ` |
145
173
146
- ### Examples:
174
+ ### Examples
175
+
147
176
1 . ** Short Option (-)** :
177
+
148
178
``` bash
149
179
chmod -R 755 directory
150
180
chown -R user:group directory
151
181
```
182
+
152
183
2 . ** Long Option (--)** :
184
+
153
185
``` bash
154
186
chmod --recursive 755 directory
155
187
chown --recursive user:group directory
156
188
```
157
189
158
- ### Key Notes:
190
+ ### Key Notes
191
+
159
192
- Short options (` - ` ) are typically more concise and can be combined (e.g., ` ls -la ` ).
160
193
- Long options (` -- ` ) are more descriptive, making scripts easier to read and understand.
161
194
0 commit comments