1
COMP 83
LINUX 1
LAB 1
Student Name: Harmanjot Singh Panjeta
Student ID: 4352404
Date: 11-02-2022
2
Contents
Section 1................................................................................................................................................................................3
Section 2.............................................................................................................................................................................. 27
Section 3.............................................................................................................................................................................. 40
Section 4.............................................................................................................................................................................. 50
3
Section 1
/
Budget
root
Payroll
Finance
Staf
HR
Data
Figure 1
Perform the following tasks using the Linux command-line tool:
4
a) Create the directory structure in Figure 1 above
b) Practicing changing directory by doing the following:
5
i. Starting with Payroll as your present working directory, change the directory to
Staff using absolute path
6
ii. From Staff, change directory to Data using relative path
7
iii. From Data, change directory to Finance using relative path
8
iv. From Finance, change directory to Data using absolute path
9
v. From Data, change directory to Staff using relative path
10
vi. From Staff, change directory to HR using relative path
11
vii. From HR, change directory to Payroll using relative path
12
viii. From Payroll, change directory to Finance using absolute path
13
ix. From Finance, change directory to Budget using relative path
14
x. From Budget, change directory to the root user directory using relative path
15
xi. From the root user directory, Change directory to the root of the Linux directory
c) In the Data directory, create the following empty files
16
i. Three hidden files: .info1, .info2, .info3
17
ii. Three regular files: data1.txt, data2.txt, data3.txt
d) Display the contents of the Data directory using the following ls commands and notice
the difference:
i. Ls
18
ii. ls -a
iii. ls -l
iv. ls -i
v. ls -al
19
vi. ls -il
20
vii. ls -ail
21
e) Copy data1.txt to record1.txt
f) Rename data2.txt to record2.txt
22
g) Delete data1.txt
23
h) Move data3.txt to the Budget directory
24
i) Move .info2 to Finance directory and rename the file .Rec2. Do this using a single
command.
25
j) Copy .info1 to HR directory
k) Delete the empty directory Staff
26
l) Delete the non-empty directory Data
27
m) Delete the Finance and HR directories to end this exercise.
28
Section 2
Perform the following task using the Linux command-line tool:
n) In the /root directory, create a directory myLabXXX (where XXX is the last 3 digit of
your student ID)
o) In the myLab directory create the following files using the vi editor:
fileA.txt fileB.txt fileC.txt
Joe Harvey 76 Edward Jones 90 Joe Mississauga
Bob Miller 45 Tom Arnold 25 Bob Ajax
Sally Shield 81 Mark Hill 61 Sally Brampton
29
Courtney Adam 56 Sharon Price 44 Courtney Scarborough
Press I to enter INSERT mode then type file data
Press ESC to return to command mode then type :wq! to save and quit file
30
cl
Press I to enter INSERT mode then type file data
Press ESC to return to command mode then type :wq! to save and quit file
31
Press I to enter INSERT mode then type file data
Press ESC to return to command mode then type :wq! to save and quit file
p) Display the content of fileA.txt, fileB.txt, and fileC.txt
32
q) Display the top 2 rows of fileA.txt
r) Display the bottom 3 lines of fileA.txt
s) Combine fileA.txt and fileB.txt
33
t) Merge fileA.txt with fileB.txt
34
u) Join fileA.txt and fileB.txt
35
v) Join fileA.txt and fileC.txt
36
w) Sort the first column of fileA.txt in alphabetical order
x) Sort the first column of fileA.txt in reverse alphabetical order
y) Sort the second column of fileA.txt in alphabetical order
37
z) Sort the second column of fileA.txt in reverse alphabetical order
aa)Sort the third column of fileA.txt in ascending order (lowest number first)
bb) Sort the third column of fileA.txt in descending order (highest number first)
38
cc)Add numbered lines to fileB.txt
dd) Perform a word count on fileB.txt
39
ee)Change Ajax to Hamilton in fileC.txt
40
41
Section 3
mkdir1. Using the vi editor, create the file budget.txt with the following content, then using an appropriate command
display the content of the file on the display. [5]
Using the snipping tool paste the command you used and the output below.
2. Using the vi editor, create the file budgetB.txt with the following content, then using an appropriate command display
the content of the file on the display. [5]
42
Using the snipping tool paste the command you used and the output below.
3. Using the two files you created, apply the appropriate command to obtain the following output. [5]
43
Using the snipping tool paste the command you used and the output below.
4. Using the two files you created, apply the appropriate command to obtain the following output [5]
44
Using the snipping tool paste the command you used and the output below.
5. Using the vi editor, create the file Sales.txt with the following content, then using an appropriate command display the
content of the file on the display. [5]
Using the snipping tool paste the command you used and the output below.
45
6. Combine budget.txt and Sales.txt to obtain the following output using the appropriate command [5]
Using the snipping tool paste the command you used and the output below.
46
7. Combine budget.txt and Sales.txt just as you did above but this time write the output to a file data3.txt, Below is an
example of what data3.txt should look like when displayed with the cat command. [3]
Using the snipping tool paste the command you used and the output below.
47
8. Sort data3.txt and write the output to a file data4.txt. then display the content of data4.txt to obtain the following output.
[3]
Using the snipping tool paste the command you used and the output below.
48
9. Sort the budgetB.txt file you created earlier to obtain the following output. [2]
Using the snipping tool paste the command you used and the output below.
49
10. Use the appropriate command to change the value 19500 to 28500 in the Sales.txt file, such that Sales.txt will be
updated as follows. [2]
Using the snipping tool paste the command you used and the output below.
50
51
Section 4
1. Create the following users with the following attributes. [5]
Username Comment Expire Date Shell
Calvin Consultant 2018-06-15 -
Joyce Engineer - -
Jillian Programmer - /bin/tcsh
Patrick - - -
Carter - - -
Use the appropriate command to display the last five users you have just created on the screen.
52
2. Display all contents (including hidden files) in Carter home directory. [5]
53
3. In what directory was the .bashrc file copied from? [5]
___________________________
4. Create a password for Jillian (use this password Pa$$word) and display the encrypted password on the screen using the
appropriate command and Linux file. [5]
54
5. Add a comment for Patrick to show Developer and configure his user account expiry date to 2019-01-01. Display the
change of Patrick user account attributes on the screen. [5]
55
6. Modify Joyce login name to JAdam. [5]usermod
56
7. Delete Carter user account and display the content of the appropriate file to verify that the account no longer exists. [5]
57
8. Lock Jillian user account and display the last five lines of the /etc/passwd file on the screen. [5]
58
9. What symbol in the /etc/passwd file indicates that Jillian account is locked? [5]
_______________!!____________________
~End of Lab~