Skip to content

Commit f39d217

Browse files
committed
Enhance formatting and clarity in Linux Permissions Guide by adding spacing and improving code block syntax
1 parent a14e210 commit f39d217

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

_posts/2024-12-11-LinuxPermissionsGuide.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ The `chmod` (change mode) command is used to change the permissions of a file or
2121
### File Permission Structure
2222

2323
Each file has three sets of permissions:
24+
2425
1. **Owner (u)**: The user who owns the file.
2526
2. **Group (g)**: The group that owns the file.
2627
3. **Others (o)**: All other users.
2728

2829
Each set has three permission types:
30+
2931
- **Read (r)**: Permission to read the file.
3032
- **Write (w)**: Permission to modify the file.
3133
- **Execute (x)**: Permission to execute the file as a program.
3234

3335
#### Example
3436

35-
```
37+
```plain-text
3638
-rw-r--r--
3739
```
40+
3841
This representation indicates:
42+
3943
- `r` and `w` for the owner (read and write permissions)
4044
- `r` for the group (read permission)
4145
- `r` for others (read permission)
@@ -54,25 +58,34 @@ chmod ugo=rwx file.txt # Set all permissions for everyone
5458
```
5559

5660
#### Numeric Method
61+
5762
Permissions can also be represented using octal numbers:
63+
5864
- `r` = 4, `w` = 2, `x` = 1
5965
- Add them together for each set.
6066

6167
Example:
68+
6269
```bash
6370
chmod 755 file.txt
6471
```
72+
6573
In this case:
74+
6675
- Owner: 7 = rwx
6776
- Group: 5 = r-x
6877
- Others: 5 = r-x
6978

7079
**Examples**:
80+
7181
- Grant full permissions to the owner, and read-only to others:
82+
7283
```bash
7384
chmod 744 file.txt
7485
```
86+
7587
- Make a script executable for everyone:
88+
7689
```bash
7790
chmod +x script.sh
7891
```
@@ -84,45 +97,60 @@ The `chown` (change owner) command is used to change the ownership of a file or
8497
### Ownership Structure
8598

8699
Each file or directory has:
100+
87101
1. **Owner**: The user who owns the file.
88102
2. **Group**: The group associated with the file.
89103

90104
### Basic Usage of `chown`
91105

92106
#### Change Owner
107+
93108
To change the owner of a file:
109+
94110
```bash
95111
chown new_owner file.txt
96112
```
97113

98114
#### Change Group
115+
99116
To change the group associated with a file:
117+
100118
```bash
101119
chown :new_group file.txt
102120
```
103121

104122
#### Change Both
123+
105124
To change both the owner and group:
125+
106126
```bash
107127
chown new_owner:new_group file.txt
108128
```
109129

110130
#### Recursive Ownership Change
131+
111132
To apply changes to a directory and all its contents:
133+
112134
```bash
113135
chown -R new_owner:new_group directory_name
114136
```
115137

116138
**Examples**:
139+
117140
- Make `john` the owner of `file.txt`:
141+
118142
```bash
119143
chown john file.txt
120144
```
145+
121146
- Change the group to `developers`:
147+
122148
```bash
123149
chown :developers file.txt
124150
```
151+
125152
- Make `john` the owner and `developers` the group of a directory and its contents:
153+
126154
```bash
127155
chown -R john:developers /project
128156
```
@@ -143,19 +171,24 @@ In Unix/Linux commands, options can be specified in two ways: short (`-`) and lo
143171
| `-` | Short options (single-letter) | `chmod -R 755 directory` (recursive) |
144172
| `--` | Long options (full-word) | `chmod --recursive 755 directory` |
145173

146-
### Examples:
174+
### Examples
175+
147176
1. **Short Option (-)**:
177+
148178
```bash
149179
chmod -R 755 directory
150180
chown -R user:group directory
151181
```
182+
152183
2. **Long Option (--)**:
184+
153185
```bash
154186
chmod --recursive 755 directory
155187
chown --recursive user:group directory
156188
```
157189

158-
### Key Notes:
190+
### Key Notes
191+
159192
- Short options (`-`) are typically more concise and can be combined (e.g., `ls -la`).
160193
- Long options (`--`) are more descriptive, making scripts easier to read and understand.
161194

0 commit comments

Comments
 (0)