You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-45Lines changed: 1 addition & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,6 @@
24
24
25
25
### a. `export`
26
26
Displays all environment variables and if you want to get detail of specific variable then use `echo $VARIABLE_NAME`
27
-
Syntax:
28
27
```bash
29
28
export
30
29
```
@@ -43,7 +42,6 @@ $ echo $SHELL
43
42
44
43
### b. `whereis`
45
44
Finds out where a specific binary is on your system.
46
-
Syntax:
47
45
```bash
48
46
whereis name
49
47
```
@@ -55,7 +53,6 @@ $ whereis php
55
53
56
54
### c. `which`
57
55
Locate a program file in the user's path. This command will prints full path of the executable(s). It does this by searching the directories listed in the environment variable PATH.
58
-
Syntax:
59
56
```bash
60
57
which program_name
61
58
```
@@ -95,7 +92,6 @@ Clears content on window
95
92
96
93
### a. `ls`
97
94
Lists your files. It has a lot of options like `-l` lists files in 'long format', which contains the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified. `-a` lists all files, including hidden files. For more information on this command check this [link](https://ss64.com/bash/ls.html)
Places standard input into file. Means that it opens the file in terminal for you to edit
128
-
Syntax:
129
123
```bash
130
124
cat > filename
131
125
```
132
126
133
127
### d. `more`
134
128
Shows the first part of a file (move with space and type q to quit)
135
-
Syntax:
136
129
```bash
137
130
more filename
138
131
```
139
132
140
133
### e. `head`
141
134
Outputs the first 10 lines of file
142
-
Syntax:
143
135
```bash
144
136
head filename
145
137
```
146
138
147
139
### f. `tail`
148
140
Outputs the last 10 lines of file. Use `-f` to output appended data as the file grows
149
-
Syntax:
150
141
```bash
151
142
tail filename
152
143
```
153
144
154
145
155
146
### g. `mv`
156
147
Moves a file from one location to other
157
-
Syntax:
158
148
```bash
159
149
mv filename1 filename2
160
150
```
161
151
Where `filename1` is the source path to the file and `filename2` is the destination path to the file.
162
152
163
153
### h. `cp`
164
154
Copies a file from one location to other
165
-
Syntax:
166
155
```bash
167
156
cp filename1 filename2
168
157
```
@@ -172,56 +161,48 @@ Where `filename1` is the source path to the file and `filename2` is the destinat
172
161
Removes a file. But if you will apply this command on a directory directory, it will gives you an error
173
162
`rm: directory: is a directory`
174
163
So in order to remove directory you have to pass `-rf` to remove all the content of the directory recursively
175
-
Syntax:
176
164
```bash
177
165
rm filename
178
166
```
179
167
180
168
### j. `diff`
181
169
Compares files, and shows where they differ
182
-
Syntax:
183
170
```bash
184
171
diff filename1 filename2
185
172
```
186
173
187
174
### k. `chmod`
188
175
Lets you change the read, write, and execute permissions on your files
189
-
Syntax:
190
176
```bash
191
177
chmod -options filename
192
178
```
193
179
194
180
### l. `gzip`
195
181
Compresses files
196
-
Syntax:
197
182
```bash
198
183
gzip filename
199
184
```
200
185
201
186
### m. `gunzip`
202
187
Un-compresses files compressed by gzip
203
-
Syntax:
204
188
```bash
205
189
gunzip filename
206
190
```
207
191
208
192
### n. `gzcat`
209
193
Lets you look at gzipped file without actually having to gunzip it
210
-
Syntax:
211
194
```bash
212
195
gzcat filename
213
196
```
214
197
215
198
### o. `lpr`
216
199
Print the file
217
-
Syntax:
218
200
```bash
219
201
lpr filename
220
202
```
221
203
222
204
### p. `lpq`
223
205
Check out the printer queue
224
-
Syntax:
225
206
```bash
226
207
lpq
227
208
```
@@ -235,7 +216,6 @@ active adnanad 59 demo 399360 bytes
235
216
236
217
### q. `lprm`
237
218
Remove something from the printer queue
238
-
Syntax:
239
219
```bash
240
220
lprm jobnumber
241
221
```
@@ -266,7 +246,6 @@ lprm jobnumber
266
246
### a. `awk`
267
247
Awk is most usefull command for handling text files. It operates on entire file line by line. By default it uses whitespace to separate the fields. The most common syntax for awk command is
@@ -295,7 +274,6 @@ For more detail on how to use `awk`, check following [link](https://www.cybercit
295
274
296
275
### b. `grep`
297
276
Looks for text inside files. You can use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines.
298
-
Syntax:
299
277
```bash
300
278
grep pattern filename
301
279
```
@@ -314,7 +292,6 @@ And `-w` to search for words only. For more detail on `grep`, check following [l
314
292
315
293
### c. `wc`
316
294
Tells you how many lines, words and characters there are in a file
317
-
Syntax:
318
295
```bash
319
296
wc filename
320
297
```
@@ -370,7 +347,6 @@ TODO
370
347
371
348
### a. `mkdir`
372
349
Makes a new directory
373
-
Syntax:
374
350
```bash
375
351
mkdir dirname
376
352
```
@@ -387,7 +363,6 @@ cd dirname
387
363
388
364
### c. `pwd`
389
365
Tells you in which directory you currently are
390
-
Syntax:
391
366
```bash
392
367
pwd
393
368
```
@@ -429,12 +404,10 @@ pwd
429
404
430
405
### a. `ssh`
431
406
ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine.
432
-
Syntax:
433
407
```bash
434
408
ssh user@host
435
409
```
436
410
This command also accepts an option `-p` that can to used to connect to specific port.
437
-
Syntax:
438
411
```bash
439
412
ssh -p port user@host
440
413
```
@@ -446,8 +419,7 @@ Return current logged in username
446
419
Allows the current logged user to change his password
447
420
448
421
### d. `quota`
449
-
Shows what your disk quota is
450
-
Syntax:
422
+
Shows what your disk quota is
451
423
```bash
452
424
quota -v
453
425
```
@@ -466,21 +438,18 @@ Displays who is online
466
438
467
439
### i. `finger`
468
440
Displays information about user
469
-
Syntax:
470
441
```bash
471
442
finger username
472
443
```
473
444
474
445
### j. `uname`
475
446
Shows kernel information
476
-
Syntax:
477
447
```bash
478
448
uname -a
479
449
```
480
450
481
451
### k. `man`
482
452
Shows the manual for specified command
483
-
Syntax:
484
453
```bash
485
454
man command
486
455
```
@@ -490,35 +459,30 @@ Shows disk usage
490
459
491
460
### m. `du`
492
461
Shows the disk usage of the files and directories in filename (du -s give only a total)
493
-
Syntax:
494
462
```bash
495
463
du filename
496
464
```
497
465
498
466
### n. `last`
499
467
Lists your last logins of specified user
500
-
Syntax:
501
468
```bash
502
469
last yourUsername
503
470
```
504
471
505
472
### o. `ps`
506
473
Lists your processes
507
-
Syntax:
508
474
```bash
509
475
ps -u yourusername
510
476
```
511
477
512
478
### p. `kill`
513
479
Kills (ends) the processes with the ID you gave
514
-
Syntax:
515
480
```bash
516
481
kill PID
517
482
```
518
483
519
484
### q. `killall`
520
485
Kill all processes with the name
521
-
Syntax:
522
486
```bash
523
487
killall processname
524
488
```
@@ -534,28 +498,24 @@ Brings the most recent job in the foreground.
534
498
535
499
### u. `ping`
536
500
Pings host and outputs results
537
-
Syntax:
538
501
```bash
539
502
ping host
540
503
```
541
504
542
505
### v. `whois`
543
506
Gets whois information for domain
544
-
Syntax:
545
507
```bash
546
508
whois domain
547
509
```
548
510
549
511
### w. `dig`
550
512
Gets DNS information for domain
551
-
Syntax:
552
513
```bash
553
514
dig domain
554
515
```
555
516
556
517
### x. `wget`
557
518
Downloads file
558
-
Syntax:
559
519
```bash
560
520
wget file
561
521
```
@@ -634,7 +594,6 @@ ${#varname} # returns the length of the value of the variable as a character
634
594
## 2.3. Functions
635
595
As in almost any programming language, you can use functions to group pieces of code in a more logical way or practice the divine art of recursion. Declaring a function is just a matter of writing function my_func { my_code }. Calling a function is just like calling another program, you just write its name.
636
596
637
-
Syntax:
638
597
```bash
639
598
functname() {
640
599
shell commands
@@ -661,7 +620,6 @@ When you will run above example the `hello` function will output "world!". The a
661
620
662
621
The conditional statement in bash is similar to other programming languages. Conditions have many form like the most basic form is `if` expression `then` statement where statement is only executed if expression is true.
663
622
664
-
Syntax:
665
623
```bash
666
624
if [expression];then
667
625
will execute only if expression is true
@@ -672,7 +630,6 @@ fi
672
630
673
631
Sometime if conditions becoming confusing so you can write the same condition using the `case statements`.
674
632
675
-
Syntax:
676
633
```bash
677
634
case expression in
678
635
pattern1 )
@@ -772,7 +729,6 @@ cd hotellogs
772
729
# 4. Debugging
773
730
You can easily debug the bash script by passing different options to `bash` command. For example `-n` will not run commands and check for syntax errors only. `-v`echo commands before running them. `-x`echo commands after command-line processing.
0 commit comments