Professional Documents
Culture Documents
19CSE101
PRITHIVI .R.S
studying B.Tech Computer Science Engineering
2
INDEX
8
1. Display the path of your current directory.
asecomputerlab@asecomputerlab-HP-ProDesk-400-G7-Microtower-
PC:~$ pwd
/home/asecomputerlab
asecoaputerlib^asecaipiiterlib-fiP-ProDe3H00-57-Micr
5. Print the path of the current directory.
aseccmputerlab@&secomputerlab-HP-ProDesk-4QQ-G7-Microtower-
PC:«/main$ pwd
/home/asecomputerlab/main
asecanpiiterlab(}asecaiiputerlab-HP-ProDesk-400-G7-Microtower-PC:*/imn$ cd dirl/dir
aseconputerlabfasecoiq)uterlab-HP-ProDesH00-G7-
MicrotoKi-PC:*/iMin/dirl/dir2/dir3$ Is
demol demo2
11. Go to Dir 2.
asecoiiputerlabSi3ecaipiiterlab-HP-Pro!}esH(}()-G7-MicrotovBr-PC>/m
12. Go to your home directory.
bsecomputerlab@asecomputerlab-HP-ProDesk-400-G7-Microtower-PC:~/nmn/dirl/dir2$ cd *■
10
13. Stay where you are, and list the contents of Dir3.
asecomputerlab@asecomputerlab-HP-ProDesk-400-G7-Microtower-PC:~$ Is main/dirl/dir2/dir3
demol demo2
14. List all the files (including hidden files) in your home
directory.
aseconputerlabQaseccaputerlab-BP-ProDesk-400-G7-Microtower-PC: Is -al
total 244
drwxr-xr-x 38 asecomputerlab asecomputerlab 4096 Dec 21 15:54 .
drwxr-xr-x 5 root root 4096 Apr 7 2022 ..
drwxrwxr-x 2 asecomputerlab asecomputerlab 4096 Oct 21 20:31 .android
-rw------- 1 asecomputerlab asecomputerlab 11113 Dec 14 11:33 ,bash_history
-rw-r—r— 1 asecomputerlab asecomputerlab 220 Dec 24 2021 .bash_logout
-rw-r—r— 1 asecomputerlab asecomputerlab 3954 Apr 1 2022 .bashrc
drwx------ 25 asecomputerlab asecomputerlab 4096 Nov 25 11:04 .cache
drwxrwxr-x 2 asecomputerlab asecomputerlab 4096 Dec 8 15:36
ch.en.u4csel9005
drwxrwxr-x 2 asecomputerlab asecomputerlab 4096 Dec 8 19:59
ch.en.u4cse21233
drwxrwxr-x 2 asecomputerlab asecomputerlab 4096 Dec 21 15:56
ch.en.u4cse22053
drwx------ 11 asecomputerlab asecomputerlab 4096 Nov 25 17:04 .config
drwxrwxr-x 4 asecomputerlab asecomputerlab 4096 Dec 2 16:15 cse
drwxrwxr-x 2 asecomputerlab asecomputerlab 4096 Nov 18 16:22 cse2
drwx------ 3 root root 4096 Oct 20 19:37 .dbus
15. Create 2a new
drwxr-xr-x file testl, type
asecomputerlab and save4096
asecomputerlab the contents
Dec 14 17:33 Desktop
jsecofUterJatJasecc!iiipiJterJal)-iiP-ProM-Jll()-57-l!icrotci
11
17. Rename test2 as test3.
asecomputerldbfasecomputerlab-HP-ProDesk-400-G7-MicrotoHe
asecoo|)iiterlabjasecflfuterlab-flP-ProDes]k-40£)-fi7-Microtowr-
20. Create a file count, with content one to twenty in words with
one line having only one number using a single command.
12
21. Copy the file count to count2 using cat command.
aseconputerlabfaseconpiiterlab-HP-ProDesk-400-G7-Microtoifer-P
22. Create another file count3 with numbers twenty one to twenty
five (in five lines).
asecomputerlab@asecomputerlab-HP-ProDesk-400-G7-Microtower-PC:-$ cat >count3
twenty one
twenty two
twenty three
twenty four
twenty five
23. Concatenate the contents of files count2 and count3 and write it
into the file countfinal.
asecouiputerlabgaseco]nputerlaib-flP-ProDesJt
25. Go to Dir2 and remove the subdirectory Dir3.
asecofuterJ#secoiiipute:lab-HP-ProDesJ(-400-G7-
Wicrotower-PC>J cdmin/dirl/dir2
aseconputeriab(?aseconputerIab-iiP-ProDesJc-400-G7-
Microtover-PO/iMin/dirI/dir2^ n remove
26. Come back to your home folder and -r dir3Dir2.
asecomputerlab@aseconputerlab-HP-ProDesk-400-G7-
Microtower-PC:»/nain/dirl/dir2$ cd *
asecomputerlab@asecomputerlab-HP-ProDesk-400-G7-
Microtower-PC:rmdir min/dirl/dir2
13
27. Display first 10 lines of the file countfinal in terminal.
asecomputerlab@asecomputerlab-HP-ProDesk-400-G7-Microtower-PC:head countfinal
one
two
three
four
five
six
seven
eight
nine
ten_
asecompiiterlab@asecomputerlab-HP-ProDesk-400-G7-Microtower-PC:~$ tac
countfinal twenty five twenty four twenty three
twenty two
twenty one
twenty
nineteen
eighteen
seventeen
sixteen
fifteen
fourteen
thirteen
twelve
eleven
ten
nine
eight
seven
six
five
four
three
two
one_
15
LAB EXERCISE-02
18
1. Create a file demo with the following contents Student Prithivi
Essentials 20 PSAT 24 Maths 35 Cultural 27 English 65
Student Raj Essentials 25 PSAT 26 Maths 31 Cultural 20 English
91
Student Sabha Essentials 19 PSAT 18 Maths 29 Cultural 15
English 47
Student Dhina Essentials 23 PSAT 15 Maths 45 Cultural 24
English 96
Student Hari Essentials 9 PSAT 7 Maths 12 Cultural 13 English 5
9
19
20
23
25
(CA) Ubuntu X + v
question-1.sh •
29 #//bin/bash 28
27 # 1. Create a file Studdetails with the following contents 26 cat > Studdetails « EOF
25 Student Alice Essentials 20 PSAT 22 Maths 34 Cultural 25 Physics 80 English 70 24 Student Bob Essentials 23 PSAT
21 Maths 32 Cultural 18 Physics 18 English 94 23 Student Boby Essentials 43 PSAT 31 Maths 22 Cultural 8 Physics 76
English 93 22 Student Clara Essentials 18 PSAT 16 Maths 27 Cultural 12 Physics 34 English
45
21 Student Dirch Essentials 25 PSAT 23 Maths 48 Cultural 25 Physics 45 English 98+
20 Student Eve Essentials 8 PSAT 6 Maths 12 Cultural 13 Physics 4 English 5 19 EOF 18
17 echo "2. Filter the details of the student Bob"
16 cat Studdetails | grep '\<Bob\>'
15 echo ""
14
13 echo "3. Find the number of students with their names containing the letter a, e or i"
12 cat Studdetails | cut -d ' ' -i 2 | grep '[aei]' | wc -1
11 echo ""
10
9 echo "4. Find the marks of students whose names starts with ‘b* Cease insensitive)"
8 cat Studdetails | grep -i '\<b.*\>'
7 echo ""
6
5 echo "5. Find the names of students whose names starts with ‘b} and ends with *y’ (case insensitive) 4 cat
Studdetails | cut -d ' ' -f 2 | grep -i ,nb.*y$'
3 echo ""
17
1. Write shell scripts for the following actions in the given order:
a. Create a file Studdetails with the following contents Student Alice
Essentials 20 PSAT 22 Maths 34 Cultural 25 Physics 80 English 70
Student Bob Essentials 23 PSAT 21 Maths 32 Cultural 18 Physics 18 English 94
Student Boby Essentials 43 PSAT 31 Maths 22 Cultural 8 Physics 76 English 93
Student Clara Essentials 18 PSAT 16 Maths 27 Cultural 12 Physics 34 English 45
Student Dirck Essentials 25 PSAT 23 Maths 48 Cultural 25 Physics 45 English 98+
Student Eve Essentials 8 PSAT 6 Maths 12 Cultural 13 Physics 4 English 5
c. Find the number of students with their names containing the letter a, e
or I
d. Find the marks of students whose names starts with ‘b’ (case
insensitive)
e. Find the names of students whose names starts with ‘b’ and ends with
‘y’ (case insensitive)
16
18
2. Write a shell script to perform the following actions in the given order:
§3 Ubuntu X
question-2.sh •
32 U 1.Create a file numericdata with the following contents
31 cat > numericdata « EOF
30 Uollam 56754 6754 7654
29 Vallihkavu 5H328 7548 45675
28 Trivandrum 16U23 6654 6754
27 Ernahulam 28796 8549 9875
26 Kayamhulam 35589 75892 3451
25 kottayam 45557 6773 6547
24 tirukulum 45675 56476 7896
23 EOF
22
21 echo "2. Display the details of Places that starts with ‘T’Ccase sensitive)"
20 cat numericdata | grep ,A7'
19 echo ""
18
17 echo "3. Display code3 in sorted order(ascending) of the places that start with ‘K’Ccase insensitive) and ends with am" 16 cat
numericdata | grep -i 'Ak.*am\>' | cut -d ' ' -f 4 | sort -n 15 echo 14
13
12 echo "4. Filter code2 that starts with 6 and ends with 4"
11 cat numericdata | cut -d ' ’ -f 3 | grep 'A6.*4$'
10 echo ""
9
8 echo "5. Filter code2 having one or more occurrence of the digit 6"
7 cat numericdata | cut -d ' ' -f 3 | grep -E '6+'
6 echo ""
5
4 echo "6. Filter all codel having one or more occurrence of the digit 5"
3 cat numericdata | cut -d 1 ' -f 2 | grep -E '5+'
2 echo ""
19
a. Create a file numericdata with the following contents Kollam 56754 6754
7654
Vallikkavu 54328 7548 45675 Trivandrum 16423 6654 6754 Ernakulam 28796
8549 9875
Kayamkulam 35589 75892 3451 kottayam 45557 6773 6547 tirukulum 45675
56476 7896
(Hint : First field is referred as Place second as code1 third as code2 and fourth as
code3)
20
3. Write a shell script to perform the following actions in the given order:
f. Write the contents of ls -la to a file named HiddenDetails
g. Write the contents of file HiddenDetails to the file HiddenFiles after replacing
multiple occurrences of space with a single space.
h. Using the file HiddenFiles, find the total number of files and folders that starts
with ‘p’(case insensitive)
i. Using the file HiddenFiles, find the names of files and folders that starts with
‘.’ and ends with ‘nda’
j. Using the file HiddenFiles, list all the directories
(The first field in ls -la denotes the permissions associated with the file. If the first
letter in permission is ‘d’ then it is a directory)
22
23
4. Write shell program to perform the following actions:
f. Write the contents of the command man sort into a file
SortManual.
g. Filter all lines form the file SortManual that starts with
‘compare’.
h. Filter all lines form the file SortManual that ends with ‘sort’.
question-M.sh
1 |.'/bin/b ash
1
2 # a. Write the contents of the command man sort into a file SortManual.
3 nan sort > SortManual
4
5 echo "b. Filter all lines form the file SortManual that starts with
‘compare’."
6 cat SortManual | grep '"compare1
7 echo
8
9 echo "c. Filter all lines form the file SortManual that ends with
‘sort’."
10 cat SortManual | grep 'sort}'
11 echo
12
13 echo "d. Display the number of lines in SortManual that has the word
‘numeric’."
14 cat SortManual | grep '\<muneric\>' | wc -l
15 echo ""
16
17 # e. Write the contents of file SortManual to the file sort after
replacing multiple occurrences of with a single
18 cat SortManual | tr -s '-' > sort
24
MySQL QUERIES
21
1) CREATE COMMAND:
mysql> create table crew (sno int not null, name varchar(10),expertise char(10),share int(5));
Query OR, 0 rows affected, 1 warning (0.20 sec)
2) ALTER COMMAND:
+-------------- -+-------------+------+-----+---------+-------+
| Type | Null | key | Default | Extra
---
+- - | - -+-- --- --+--- ----
| Field - +- - +
1 sno i int i NO 1 1 NULL 1 i
1 name i varchar(10) i YES 1 1 NULL 1 1
1 expertise i char(10) i YES 1 1 NULL 1 1
1 share i int i YES 1 1 NULL 1 1
1 experience_in_years i int i YES 1 1 NULL 1 1
5 rows in set (0.00 sec)
_ _ —
-+-- ---+ - ---1-- ----
+- - - --- +
2.4 RENAME:
23
3) DROP TABLE:
mysql> drop table crew;
Query Ok, 0 rows affected (0.05 sec)
4) TRUNCATE:
mysql> create table chocolates Csno int not null, brand varchar(20) , price intC4) 3; Query OK, 0
rows affected, 1 warning C0.O4 sec}
mysql> desc chocolates;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| sno | int | NO | | NULL | |
j brand j varchar(20) j YES | j NULL
j price j int j YES j | NULL
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec}
mysql> insert into chocolates valuesCl,"fivestar",10),
-> C2,"munch" ,5)
-> ,
-> C3,"dairy milk" ,20);
Query OK, 3 rows affected C0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from chocolates;
+-----+------------+-------+
| sno | brand | price |
+-----+------------+-------+
| 1 | fivestar | 10 |
2 j munch j 5 j
j 3 j dairy milk j 20 j
+-----+------------+-------+
3 rows in set C0.00 sec)
mysql> truncate table chocolates;
Query OK, 0 rows affected CO.04 sec)
mysql> select * from chocolates;
Empty set C0.O0 sec)
5) INSERT :
6) UPDATE :
26
7.1 DELETING A PARTICULAR RECORD USING CONDITION
| PATIENT | DOB
| Selena | 2003-05-09 | |
Tate | 1985-11-05 |
8) SELECT :
27
8.3 SELECTING DISTINCT FIELDS :
9) OPERATORS
9.1 AND :
28
mysql> SELECT * FROM HEROES;
-+--------- -+---------
SNO FNAME AGE
1 | LNAME | PLACE 1
11 SON | GOKU | JAPAN 1 50
21 IRON | MAN | USA 1 48
31 BLACK | PANTHER | WAKANDA 1 38
41 THOR | NULL NULL 1 NULL
51 SPIDER | MAN | USA 1 20
61 ANT | MAN | USA 1 40
71 HULK | NULL | USA 1 45
_ _ _ -+--------- -+--------- _
7 rows in set CO.00 sec)
mysql> SELECT * FROM HEROES WHERE LNAME = 'MAN' AND AGE > 40;
-+------+
| SNO FNAME LNAME | PLACE 1 AGE |
1 1
CM 1 11 IRON 1 MAN | USA 1
1 + —
1 1
1 -------+- 1
h - + 1
1 row in set (0.00 sec) 1 -C=
1 00 i
+ — H
9.2 OR :
11
SON | | JAPAN |
50
GOKU |
IRON MAN | USA
4 rows in set (0-00 sec) 48
12 j
SPIDER | MAN | USA
15 20
j
MAN 1 USA |
-4--------J---
40
16
+------J
ANT |
L--------+ .
j
29
9.3 NOT :
mysql> SELECT * FROM HEROES WHERE LNAME = 'HAN' OR NOT PLACE = 'JAPAN
T-----T-------- T------- T-------
T-----T
| SNO | | | 1 AGE
FNAME LNAME PLACE |
+ 4- 4- 4- 4- 4-
T
10.1 IS NULL :
10.2 IS NOT NULL :
SON 1 JAPAN 1 50
IRON 1 USA 1 48
BLACK 1 WAKANDA 1 38
SPIDER1 USA 1 20
ANT 1 USA 1 40
_ _ _ _
5 rows in set CO.00 sec)
32
mysql> SELECT * FROM HEROES WHERE PLACE LIKE 'U%A'; | SNO | FNAME
33
12) IN OPERATOR :
12.1 IN :
mysql> SELECT * FROM HEROES WHERE PLACE IN ('USA','JAPAN');
+------ -+--------- +-------+ ------+
¥------- | PLACE | AGE |
| SNO | FNAME
-L -4- | LNAME |
- -L
12.2 NOT IN :
13.1 BETWEEN :
BETWEEN 40 AND 50;
mysql> SELECT * FROM HEROES WHERE AGE
L _L __l_
r n r n r T T
i n
FNAME LNAME PLACE | ■ 1
| SNO ■ AGE
i
M r H r H r +- " + 1
SON GOKU JAPAN | 50
1 2 IRON MAN USA 48 1
1 6 ANT MAN USA 40 1
45
w
m
13.2 NOT BETWEEN :
■ ■ ■ i ii
HULK
L J
NULL
L 4 L
USA | 1
-J-
T ’T T t T” ”—- T
| SNO | FNAME | LNAME | PLACE | AGE |
-L
T ' Tt T T” ’ T