-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathlab
More file actions
604 lines (427 loc) · 9.39 KB
/
lab
File metadata and controls
604 lines (427 loc) · 9.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
+
+Lab 1:
Create ec2 vm and connect using ssh
Lab 2:
hostname
hostname -i
cat /etc/lsb-release
ip addr
whoami
uname -a
Lab 3:
Directory command
#Create directory
mkdir test
#Change directory
cd test
#list direcotry command
ls
ls -ltr
#hidden file
ls -la
#Come out from directory
cd ..
#Check the current directory
pwd
#Trigger command for other
ls /etc
#Check system time
date
#Read a file
cat /etc/sudoers
#Read log file
cat /etc/sudoers
#live logs
tail -f /var/log/dmesg
#in linux
ctrl+c
#help page
man ls
man pwd
man tail
Lab4
sudo cat /etc/sudoers
#login as superuser
sudo su
#Add
adduser training
#It will prompt for password and info
#login as that user
su training
sudo cat /etc/sudoers
exit
exit
#delete the user
Sudo deluser amit
#Check all the user
sudo cat /etc/passwd
LAb 5
touch sample.txt # Create a file
echo "Hello World" > sample.txt
cat sample.txt
head -n 1 sample.txt
tail -n 1 sample.txt
Lab 6
### 3. File Management
mkdir testdir
#copy the file
cp sample.txt testdir/
#renaming the file or moving the file
mv testdir/sample.txt testdir/sample-renamed.txt
#removing the file
rm testdir/sample-renamed.txt
#remvoing the directory
rm testdir/sample-renamed.txt
Lab 7
### 4. File Permissions
touch myfile
chmod 744 myfile # Set file permissions
ls -l myfile
chown $USER myfile # Change ownership
### 5. Searching Files and Text
grep root /etc/passwd # Search for 'root' in file
find /etc --name passwd # Find file named passwd
### 6. System Information
top -b -n1 | head -n 10 # View CPU usage
free -h # Show memory usage
uptime # System uptime
df -h # Disk usage
du -sh * # Disk usage by folder
---------------
grep command
1) grep command
grep -r root /etc/
grep root /etc/passwd
grep -i root /etc/passwd
grep -i Root /etc/passwd
grep -n root /etc/passwd
grep -irn root /etc
-----------
find /etc -name passwdfind -
find /etc -name *.allow
find /etc -iname pAsswd
find /var/log/ -iname dmesg
find /etc -type d
--------------------
touch dep.yaml
ls -l dep.
chmod 400 dep.yaml
chmod 644 dep.yaml
chmod 777 dep.yaml
-------------------
chown
chown ubuntu dep.yaml
chown ubuntu:ubuntu dep.yaml
chown amit dep.yaml
-------------
sudo du /etc
sudo du -h /etc
sudo du -sh /etc
du -sh /home/ubuntu
sudo df -h
------------------
sudo su
-------------------------------------
09/06
Lab1
open a file using vi editor:
vi test
To go in insert mode press i
Then type following
Line1
Line2
Line3
Go to the normal mode while press esc key
To save and exit from the file you will press :wq
Lab2: Don;t want to save the latest change
vi test
Press "i" to enable the insert mode
Add few line
Line1
Line2
Line3
Line4
Line5
I don't want save latest changes
esc :q!
Lab3:
sudo vi /etc/sudoers
Press "i" ,and type below new line
# new code
Try to save that file esc+:wq
it will give a error read only file,
When you want to override readonly file
esc+:wq!
Lab4
vi test
Line1
Line2
Line3
COpy the line3, take the cursor to that line using keyboard, then press"yy"
whereever you want to paste, press "p"
esc+ :wq
vi test
Line1
Line2
Line3
Cut the line3, take the cursor to that line using keyboard, then press"dd"
whereever you want to paste, press "p"
esc+:wq
Lab 5
sudo apt update
sudo yum update
sudo dnf update
you want to install java
sudo apt-get install openjdk-17-jdk
sudo yum install openjdk-17-jdk
sudo dnf instalal openjdk-17-jdk
Lab 6:
Install this package "docker-ce"
You can use a shebang to tell Linux which interpreter is needed to run the script
Lab 7:
vi test.sh
ls
date
apt-g
et update
save the file esc+:wq
./test.sh
It will give error, read write but no excute writes
chmod +x test.sh
ls -l test.sh
./test.sh
--------------------------------------------------
Go and write the script to install vim
#!/bin/bash
sudo apt-get update
sudo apt-get install vim -y
Write a shell script to find a file "passwd" in /etc directory
vi filesearch.sh
Press i to enable insert mode
Copy and paste two line code below mentioned
#!/bin/bash
find /etc/ -name passwd
save file esc :wq
chmod for execution rithts
chmod +x vim.sh
./vim.sh
-------------------
Write a code to find the error message in /var/log
#!/bin/bash
grep -ir error /var/log
----------------------------------
11/06
Lab1: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/linux-file-transfer-scp.html
LAb2
dpkg -s apache2
dpkg -s apache2 &> /dev/null
echo $?
vi test.sh
#Copy the below code
chmod +x
fi
fi
#Save the code
chmod +x test.sh
./test.sh
dpkg -s apache2
dpkg -s apache2 &> /dev/null
echo $?
Lab3:
vi checkpack.sh
#!/bin/bash
# Function to check and install a package
install_package() {
local package_name=$1
if dpkg -s "$package_name" &> /dev/null; then
echo "$package_name is already installed. ✅ Success"
else
echo "$package_name not found. Installing..."
sudo apt update && sudo apt install -y "$package_name"
if [ $? -eq 0 ]; then
echo "$package_name installed successfully. ✅ Success"
else
echo "$package_name installation failed. ❌"
fi
fi
}
# Ask user for package name
read -p "Enter the package name you want to install: " pkg
install_package "$pkg"
chmod +x checkpack.sh
./checkpack.sh
Lab 4
#!/bin/bash
# Function 1: Check if the package is already installed
is_installed() {
local package=$
1
dpkg -s "$package" &> /dev/null
return $?
}
# Function 2: Check if the package is available in the remote apt repository
is_installed() {
local package=$1
dpkg -s "$package" &> /dev/null
return $?
}
# Function 3: Install the package if not installed and available
install_package() {
local package=$1
if is_installed "$package"; then
echo "$package is already installed. ✅"
else
echo "$package is not installed. Checking availability in the repo..."
if is_available_in_repo "$package"; then
echo "$package is available. Installing..."
sudo apt update && sudo apt install -y "$package"
if [ $? -eq 0 ]; then
echo "$package installed successfully. ✅"
else
echo "Failed to install $package. ❌"
fi
else
echo "$package is not available in the repository. ❌"
fi
fi
}
# Read multiple package names from user (space-separated)
read -p "Enter package names (space-separated): " -a packages
# Loop through all provided package names
for pkg in "${packages[@]}"; do
echo "-----------------------------"
echo "Processing: $pkg"
install_package "$pkg"
echo "-----------------------------"
done
-------------------------------------------------------------
12/06
Lab1
1)
git --version
mkdir test
cd test
git status
#It will give error not a git repository
ls -la
#check any .git subdirectory is there or not
git init
ls -la
git status
#Check error message not a git diretory is coming or not
---------------------------
Lab2:
git config --global user.name "Your Name"
git config --global user.name "yourname@example.com"
---------------------
Lab3:
touch code
git status
#Untracked file
git add code
git status
#Changes to comitted message come
touch code1
git add code1
git status
-----------------------------------
Lab 4:
git commit -m "addingcode"
git status
git log
git reflog
git show <commit id from reflog>
example
git show 48010e2
https://www.openwriteup.com/?page_id=1075
https://www.openwriteup.com/?page_id=1081
-------------------------------------------------
Lab 5
vi code
#!/bin/bash
date
Save the file
git add code
git commit -m "changing"
git status
git log
git reflog
git diff <id1> <id2>
#example
git diff 693431c a96635b
---
ssh-keygen -t rsa
cat /home/ubuntu/.ssh/id_rsa.pub
----------------------------------------------------------------------------------------------------------------------------------------------------
16/06
#How to initate the git repo
mkdir test
cd test
git status
git init
cd ..
#If you are goin
git statusg outside from that directory, you are going out of scope
git status
cd test
--------------------
Lab2
git config --global user.name amit
git config --global user.email amit@ow.com
git config --global --list
touch codefile
git add codefile
git status
git commit -m "adding"
git log
git reflog
---------------------------
git reflog
git show commitid
#for example
-------------------------
vi codefile
#!/bin/bash
echo "hell"
git add .
git commit -m "add"
git reflog
--------------------
Lab 4
cat .git/configg
#Copy the git remote command from github.com
git remote add origin url
cat .git/config
git branch
git branch -M main
git branch
------------------
git push -u origin main
ssh-keygen -t rsa
cat /home/ubuntu/.ssh/id_rsa.pub
-----------------
Try this
pwd
touch newcode
mkdir newdir
touch newdir/file
git add .
git commit -m "changes done"
git push -u origin main
#Check your github repo
git log
git status
git reflog
--------------
18/06
git clone https://github.com/amitopenwriteup/java11-examples.git
#Downloading the latest package defination
sudo apt-get update
#Installing the java
sudo apt-get install openjdk-17-jdk -y
#Install maven
sudo apt-get install maven -y
cd java11-examples
mvn clean package
#Check for jar file
ls target/