0% found this document useful (0 votes)
22 views

Lab Assignment_1 - Solution

Uploaded by

hnour8631
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lab Assignment_1 - Solution

Uploaded by

hnour8631
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1st year of the first cycle Higher School of Computer Science

Course : Introduction to operating system 1 Sidi Bel Abbes (ESI-SBA)

Lab assignment N°1


Intro. To the Linux system : log in, log out, basic commands (Solution)
Module 1 :

1. Log into your Linux account.


Solution.
The log in account and password will be discussion within the first Lab session.
2. Create a file named Lab1 by using the script utility.
Solution.
script Lab1
3. Show the ID number of the terminal that you are using.
Solution.
who
4. Show your user name (only your user name, nothing else should show up).
Solution.
whoami
5. Show all the users who are currently logged in, use the utility that display’s the user’s name.
Solution.
finger
6. Exit from the script utility.
Solution.
exit
7. Start the script utility again, make sure to append to the same file Lab1 so you don’t lose
your previous work.
Solution.
script -a Lab1

8. Use one command to show the calendar for the previous month, current month, and next
month. To do this step, you will first need to look up the man page of the utility in order to
find the right option. Don’t show the man page in the script output file (look up the man
page before starting script).
Solution.
cal -3
9. Start the calculator and show the result of the division problem: 1 / 3, show the result with 2
digits after the decimal point.
Solution.
bc
scale=2
1/3
quit

10. Show the current date and time.


Solution.
date
11. End the script session.
Solution.
exit

Module 2 :

Figure 1 Lab-1 Directory tree.

Perform the following tasks using the Linux command-line tool

a) Create the directory structure in Figure 1 above.


Solution.
mkdir ESI-SBA
mkdir Service
mkdir ESI-SBA/Teachers ESI-SBA/Students ESI-SBA/Admins
mkdir Service/Staff Service/Data
# You can use ls to figure out the created directories.
b) Practicing changing directory by doing the following :
 Start with Students as the present working directory, change the directory to Staff
using absolute path.
Solution.
pwd
# You will figure out in your terminal: /home/user/ESI-SBA/Students
cd /home/user/Service/Staff
pwd
# You will figure out in your terminal: /home/user/Service/Staff
 From Staff, change directory to Data using relative path.
Solution.
pwd
# You will figure out in your terminal: /home/user/Service/Staff
cd ~/Service/Data
pwd
# You will figure out in your terminal: /home/user/Service/Data
 From Data, change directory to ESI-SBA using relative path.
Solution.
pwd
# You will figure out in your terminal: /home/user/Service/Data
cd ~/ESI-SBA
pwd
# You will figure out in your terminal: /home/user/ESI-SBA

 From ESI-SBA, change directory to Data using absolute path.


Solution.
pwd
# You will figure out in your terminal: /home/user/ESI-SBA
cd /home/user/Service/Data
pwd
# You will figure out in your terminal: /home/user/Service/Data

 From Data, change directory to Staff using relative path.


Solution.
pwd
# You will figure out in your terminal: /home/user/Service/Data
cd ../Staff
pwd
# You will figure out in your terminal: /home/user/Service/Staff

 From Staff, change directory to Service using relative path.


Solution.
pwd
# You will figure out in your terminal: /home/user/Service/Staff
cd ..
pwd
# You will figure out in your terminal: /home/user/Service

 From Service, change directory to Students using relative path.


Solution.
pwd
# You will figure out in your terminal: /home/user/Service
cd ../ESI-SBA/Students
pwd
# You will figure out in your terminal: /home/user/ESI-SBA/Students

 From Students, change directory to ESI-SBA using absolute path.


Solution.
pwd
# You will figure out in your terminal: /home/user/ESI-SBA/Students
cd /home/user/ESI-SBA
pwd
# You will figure out in your terminal: /home/user/ESI-SBA
 From ESI-SBA, change directory to Teachers using relative path.
Solution.
pwd
# You will figure out in your terminal: /home/user/ESI-SBA
cd ./Teachers (or : cd Teachers)
pwd
# You will figure out in your terminal: /home/user/ESI-SBA/Teachers

 From Teachers, change directory to the home user directory using relative path.
Solution.
pwd
# You will figure out in your terminal: /home/user/ESI-SBA/Teachers
cd ../.. (or : cd ~)
pwd
# You will figure out in your terminal: /home/user

 From the home directory, Change directory to the root of the Linux directory.
Solution.
pwd
# You will figure out in your terminal: /home/user/
cd ../.. (or : cd / )
pwd
# You will figure out in your terminal: /

c) In the Data directory, create the following empty files


 Three regular files: data1.txt, data2.txt, data3.txt
Solution.
pwd
cd /home/user/Service/Data
touch data1.txt data2.txt data3.txt
 Three hidden files: .info1, .info2, .info3
Solution.
touch .info1 .info2 .info3
 Write some line of words in both data1.txt and data2.txt regular files
Solution.
cat > data1.txt
Hello Students !!!
Ctrl –c
cat > data2.txt
Welcome to ESI-SBA !!!
Ctrl -c
 Rewrite some other line of words in data1.txt with overwriting the previous content,
and in data2.txt with appending text.
Solution.
cat > data1.txt
First Lab session !!!
Ctrl –c
cat >> data2.txt
School of computer science !!!
Ctrl –c

 Display the content of both aforementioned two files using more than one
command-line.
Solution.
cat data1.txt data2.txt (more or less can be also employed !!! )

d) Display the contents of the Data directory using the following ls commands and notice the
difference: ls; ls -l; ls -i; ls -al; ls -il; ls -ail
Solution.
Will be figured out within the Lab session.
e) Copy data1.txt to record1.txt
Solution.
cp data1.txt record1.txt
f) Rename data2.txt to record2.txt
Solution.
rename data2.txt record2.txt
g) Delete data1.txt
Solution.
rm data1.txt
h) Move data3.txt to the Teachers directory
Solution.
mv data3.txt /home/user/ESI-SBA/Teachers (or : mv data3.txt ../../ESI-SBA/Teachers)
i) Move .info2 to ESI-SBA directory and rename the file .Rec2. Do this using a single command.
Solution.
mv .info2 ../../ESI-SBA/Rec2
j) Copy .info1 to Service directory.
Solution.
cp .info1 ..
k) Delete the empty directory Staff.
Solution.
rmdir ../Staff
l) Delete the non-empty directory Data.
Solution.
rm -r .
m) Recursively list directory tree.
Solution.
cd ~
ls -R
n) Delete the ESI-SBA and Service directories to end this Lab.
Solution.
rm –r ESI-SBA Service

You might also like