aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2021-08-01-linux-cheatsheet.md
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2023-05-23 01:48:05 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2023-05-23 01:48:05 +0200
commit6056258a66ac016c1294e2fd88425f90098cd1f9 (patch)
treef9805fa25f05b21295e56bf57885f5d8dc237d8b /content/posts/2021-08-01-linux-cheatsheet.md
parent4794dd34e74f3e75d0a62556a093514ee25df8e7 (diff)
downloadmitjafelicijan.com-6056258a66ac016c1294e2fd88425f90098cd1f9.tar.gz
Fixed a bunch of content headings
Diffstat (limited to 'content/posts/2021-08-01-linux-cheatsheet.md')
-rw-r--r--content/posts/2021-08-01-linux-cheatsheet.md141
1 files changed, 35 insertions, 106 deletions
diff --git a/content/posts/2021-08-01-linux-cheatsheet.md b/content/posts/2021-08-01-linux-cheatsheet.md
index 1645eaf..8c0d125 100644
--- a/content/posts/2021-08-01-linux-cheatsheet.md
+++ b/content/posts/2021-08-01-linux-cheatsheet.md
@@ -5,7 +5,7 @@ date: 2021-08-01
5draft: false 5draft: false
6--- 6---
7 7
8##### Generate SSH key 8**Generate SSH key**
9 9
10```bash 10```bash
11ssh-keygen -t ed25519 -C "your_email@example.com" 11ssh-keygen -t ed25519 -C "your_email@example.com"
@@ -16,9 +16,7 @@ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
16 16
17Note: By default SSH keys get stored to `/home/<username>/.ssh/` folder. 17Note: By default SSH keys get stored to `/home/<username>/.ssh/` folder.
18 18
19 19**Login to host via SSH**
20
21##### Login to host via SSH
22 20
23```bash 21```bash
24# connect to host as your local username 22# connect to host as your local username
@@ -31,9 +29,7 @@ ssh <user>@<host>
31ssh -p <port> <user>@<host> 29ssh -p <port> <user>@<host>
32``` 30```
33 31
34 32**Execute command on a server through SSH**
35
36##### Execute command on a server through SSH
37 33
38```bash 34```bash
39# execute one command 35# execute one command
@@ -43,66 +39,50 @@ ssh root@100.100.100.100 "ls /root"
43ssh root@100.100.100.100 "cd /root;touch file.txt" 39ssh root@100.100.100.100 "cd /root;touch file.txt"
44``` 40```
45 41
46 42**Displays currently logged in users in the system**
47
48##### Displays currently logged in users in the system
49 43
50```bash 44```bash
51w 45w
52``` 46```
53 47
54 48**Displays Linux system information**
55
56##### Displays Linux system information
57 49
58```bash 50```bash
59uname 51uname
60``` 52```
61 53
62 54**Displays kernel release information**
63
64##### Displays kernel release information
65 55
66```bash 56```bash
67uname -r 57uname -r
68``` 58```
69 59
70 60**Shows the system hostname**
71
72##### Shows the system hostname
73 61
74```bash 62```bash
75hostname 63hostname
76``` 64```
77 65
78 66**Shows system reboot history**
79
80##### Shows system reboot history
81 67
82```bash 68```bash
83last reboot 69last reboot
84``` 70```
85 71
86 72**Displays information about the user**
87
88##### Displays information about the user
89 73
90```bash 74```bash
91sudo apt install finger 75sudo apt install finger
92finger <username> 76finger <username>
93``` 77```
94 78
95 79**Displays IP addresses and all the network interfaces**
96
97##### Displays IP addresses and all the network interfaces
98 80
99```bash 81```bash
100ip addr show 82ip addr show
101``` 83```
102 84
103 85**Downloads a file from an online source**
104
105##### Downloads a file from an online source
106 86
107```bash 87```bash
108wget https://example.com/example.tgz 88wget https://example.com/example.tgz
@@ -110,9 +90,7 @@ wget https://example.com/example.tgz
110 90
111Note: If URL contains ?, & enclose the URL in double quotes. 91Note: If URL contains ?, & enclose the URL in double quotes.
112 92
113 93**Compress a file with gzip**
114
115##### Compress a file with gzip
116 94
117```bash 95```bash
118# will not keep the original file 96# will not keep the original file
@@ -122,9 +100,7 @@ gzip file.txt
122gzip --keep file.txt 100gzip --keep file.txt
123``` 101```
124 102
125 103**Interactive disk usage analyzer**
126
127##### Interactive disk usage analyzer
128 104
129```bash 105```bash
130sudo apt install ncdu 106sudo apt install ncdu
@@ -133,9 +109,7 @@ ncdu
133ncdu <path/to/directory> 109ncdu <path/to/directory>
134``` 110```
135 111
136 112**Install Node.js using the Node Version Manager**
137
138##### Install Node.js using the Node Version Manager
139 113
140```bash 114```bash
141curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 115curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
@@ -144,9 +118,7 @@ source ~/.bashrc
144nvm install v13 118nvm install v13
145``` 119```
146 120
147 121**Too long; didn't read**
148
149##### Too long; didn't read
150 122
151```bash 123```bash
152npm install -g tldr 124npm install -g tldr
@@ -154,17 +126,13 @@ npm install -g tldr
154tldr tar 126tldr tar
155``` 127```
156 128
157 129**Combine all Nginx access logs to one big log file**
158
159##### Combine all Nginx access logs to one big log file
160 130
161```bash 131```bash
162zcat -f /var/log/nginx/access.log* > /var/log/nginx/access-all.log 132zcat -f /var/log/nginx/access.log* > /var/log/nginx/access-all.log
163``` 133```
164 134
165 135**Set up Redis server**
166
167##### Set up Redis server
168 136
169```bash 137```bash
170sudo apt install redis-server redis-tools 138sudo apt install redis-server redis-tools
@@ -180,9 +148,7 @@ redis-cli get mykey
180redis-cli 148redis-cli
181``` 149```
182 150
183 151**Generate statistics of your webserver**
184
185##### Generate statistics of your webserver
186 152
187```bash 153```bash
188sudo apt install goaccess 154sudo apt install goaccess
@@ -206,50 +172,38 @@ goaccess \
206rm /var/log/nginx/access-all.log 172rm /var/log/nginx/access-all.log
207``` 173```
208 174
209 175**Search for a given pattern in files**
210
211##### Search for a given pattern in files
212 176
213```bash 177```bash
214grep -r ‘pattern’ files 178grep -r ‘pattern’ files
215``` 179```
216 180
217 181**Find proccess ID for a specific program**
218
219##### Find proccess ID for a specific program
220 182
221```bash 183```bash
222pgrep nginx 184pgrep nginx
223``` 185```
224 186
225 187**Print name of current/working directory**
226
227##### Print name of current/working directory
228 188
229```bash 189```bash
230pwd 190pwd
231``` 191```
232 192
233 193**Creates a blank new file**
234
235##### Creates a blank new file
236 194
237```bash 195```bash
238touch newfile.txt 196touch newfile.txt
239``` 197```
240 198
241 199**Displays first lines in a file**
242
243##### Displays first lines in a file
244 200
245```bash 201```bash
246# -n <x> presents the number of lines (10 by default) 202# -n <x> presents the number of lines (10 by default)
247head -n 20 somefile.txt 203head -n 20 somefile.txt
248``` 204```
249 205
250 206**Displays last lines in a file**
251
252##### Displays last lines in a file
253 207
254```bash 208```bash
255# -n <x> presents the number of lines (10 by default) 209# -n <x> presents the number of lines (10 by default)
@@ -259,17 +213,13 @@ tail -n 20 somefile.txt
259tail -f somefile.txt 213tail -f somefile.txt
260``` 214```
261 215
262 216**Count lines in a file**
263
264##### Count lines in a file
265 217
266```bash 218```bash
267wc -l somefile.txt 219wc -l somefile.txt
268``` 220```
269 221
270 222**Find all instances of the file**
271
272##### Find all instances of the file
273 223
274```bash 224```bash
275sudo apt install mlocate 225sudo apt install mlocate
@@ -277,49 +227,37 @@ sudo apt install mlocate
277locate somefile.txt 227locate somefile.txt
278``` 228```
279 229
280 230**Find file names that begin with ‘index’ in /home folder**
281
282##### Find file names that begin with ‘index’ in /home folder
283 231
284```bash 232```bash
285find /home/ -name "index" 233find /home/ -name "index"
286``` 234```
287 235
288 236**Find files larger than 100MB in the home folder**
289
290##### Find files larger than 100MB in the home folder
291 237
292```bash 238```bash
293find /home -size +100M 239find /home -size +100M
294``` 240```
295 241
296 242**Displays block devices related information**
297
298##### Displays block devices related information
299 243
300```bash 244```bash
301lsblk 245lsblk
302``` 246```
303 247
304 248**Displays free space on mounted systems**
305
306##### Displays free space on mounted systems
307 249
308```bash 250```bash
309df -h 251df -h
310``` 252```
311 253
312 254**Displays free and used memory in the system**
313
314##### Displays free and used memory in the system
315 255
316```bash 256```bash
317free -h 257free -h
318``` 258```
319 259
320 260**Displays all active listening ports**
321
322##### Displays all active listening ports
323 261
324```bash 262```bash
325sudo apt install net-tools 263sudo apt install net-tools
@@ -327,30 +265,21 @@ sudo apt install net-tools
327netstat -pnltu 265netstat -pnltu
328``` 266```
329 267
330 268**Kill a process violently**
331
332##### Kill a process violently
333 269
334```bash 270```bash
335kill -9 <pid> 271kill -9 <pid>
336``` 272```
337 273
338 274**List files opened by user**
339
340##### List files opened by user
341 275
342```bash 276```bash
343lsof -u <user> 277lsof -u <user>
344``` 278```
345 279
346 280**Execute "df -h", showing periodic updates**
347
348##### Execute "df -h", showing periodic updates
349 281
350```bash 282```bash
351# -n 1 means every second 283# -n 1 means every second
352watch -n 1 df -h 284watch -n 1 df -h
353``` 285```
354
355
356