Lab 03 OS-Sum2024

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Lab 03: Shell Programming

Course: OPERATING SYSTEM


Lecturer: Hoai-Vu Nguyen, vunh@fpt.edu.vn

Exercise 1:
Write a shell script to check if today is weekend or weekday?
Date time: Wed 12 Jun 2024 10:02:05 AM +07
Today is a WEEKDAY!

Exercise 2:
Write a shell script to display the menu as follows. Then complete the task when user
choose each one.
1. Create files: t1.c, t2.cpp, t3.c; and folder: F1, Baitap, newF.
2. List all C files?
3. List all folders?
4. Show the kernel and version.
5. Exit

MENU
1. Create files: t1.c, t2.cpp, t3.c; and folder: F1, Baitap, newF
2. List all C files?
3. List all folders?
4. Show the kernel and version.
5. Exit
Choose: 1
Files & Folders created!

MENU
1. Create files: t1.c, t2.cpp, t3.c; and folder: F1, Baitap, newF
2. List all C files?
3. List all all folders?
4. Show the kernel and version.
5. Exit
Choose: 2
C files: t1.c t3.c

MENU
1. Create files: t1.c, t2.cpp, t3.c; and folder: F1, Baitap, newF
2. List all C files?
3. List all all folders?
4. Show the kernel and version.
5. Exit
Choose: 3
Folders: F1 Baitap newF

MENU
1. Create files: t1.c, t2.cpp, t3.c; and folder: F1, Baitap, newF
2. List all C files?
3. List all all folders?
4. Show the kernel and version.
5. Exit
Choose: 4
Kernel & Version:Linux version 5.15.0-107-generic…

MENU
1. Create files: t1.c, t2.cpp, t3.c; and folder: F1, Baitap, newF
2. List all C files?
3. List all all folders?
4. Show the kernel and version.
5. Exit
Choose: 5
Bye bye

Exercise 3:
Code a program to check the input name is a file, a folder or the other case.
If it is a file, then display the 3 first lines of the file’s content.
If it is a folder then display all files and folders belong to this folder. Moreover, if it is a
folder you must display all its empty folders in detail and number of empty folders. Then,
delete all above empty folders.

Please enter file name: afile


afile does not exist, or it is neither an ordinary file not a
directory.
Do you want to continue(y/n)?
y

Please enter file name: case_demo


case_demo is an ordinary file.
2 first lines of case_demo’s content:
hihihi
33333333333
Two two two

Do you want to continue(y/n)?


y

Please enter file name: dir1


dir1 is a directory.
- List subdir and files in dir1:
+ Folder: Baitap
+ Folder: newfolder
+ Folder: temp
+ File: test.txt
+ File: demo.sh
+ File: dm1.sh
- Empty folders are:(2)
newfolder
temp
- 2 empty folder(s) deleted

Do you want to continue(y/n)?


N

Submission:
You should capture the result screen (code and run all cases) of each exercise and include
in your DOCX file, and upload to CMS. Your created file should be named like <class>-
<name><roll number>-Lab-03,
e.g. SE1920-QuangTV-HE190023-Lab02.DOCX

You might also like