Operating System Lab: Fall - 2020
Operating System Lab: Fall - 2020
Operating System Lab: Fall - 2020
The objective of current lab is understanding the concept of streams, handling the
data. To implement the concept of redirections trough operators. There is also
portion in which we will see the concept of shell programming.
Date Time
$ date
Description: Prints the system date and time.
Calendar
$ cal
Description: Prints an ASCII calendar of the current month
cat Command
Page 1 of 6
Operating System Lab Lab – 5
Fall - 2020 Streams, Redirections, Shell Programming
You can see the content file by using cat command and see the updated
file.
head
Syntax: $ head [option] [Filename]
Description: “head” displays the top part of a file. By default it shows the first 10 lines. -n
allows you to change the number of lines to be shown.
Page 2 of 6
Operating System Lab Lab – 5
Fall - 2020 Streams, Redirections, Shell Programming
You can customize the number of lines to display just mentioned the
numbers of lines as below.
Tail
Syntax: $ tail [option] [Filename]
Description: Display last 10 (by default) lines of a file. Same as head command.
You can customize the number of lines to display just mentioned the
numbers of lines as below.
TASK 01
Creating three files file1, file2 and file3. Place some contents and merge into new file.
Page 3 of 6
Operating System Lab Lab – 5
Fall - 2020 Streams, Redirections, Shell Programming
sort
Example: Create text file sname as follows
$cat > sname
b
a
c
d
Press CTRL + D to save.
LAB TASK 02
Create text file studentName as follows
virk
ash
zebra
babu
Page 4 of 6
Operating System Lab Lab – 5
Fall - 2020 Streams, Redirections, Shell Programming
LAB TASK 03
LAB TASK 04
Shell Scripts
Variables in Shell
(1)System variables –
Created and maintained by Linux itself. This type of variable defined in CAPITAL
LETTERS.
(2) User defined variables (UDV) –
Created and maintained by user. This type of variable defined in lower letters. You
can see system variables by giving command like $ set, some of the important
System variables are: HOME, USER
NOTE that some of the above settings can be different in your PC/Linux
environment. You can print any of the above variables contains as follows:
Execute following.
$ echo $USERNAME
$ echo $HOME
$ 10=no # Error, NOT Ok, Value must be on right side of = sign To define variable
Page 5 of 6
Operating System Lab Lab – 5
Fall - 2020 Streams, Redirections, Shell Programming
Class Activity:05
Class Activity:06
Instructor:
Engr.Khateeb Khan
Faculty of Computing, Riphah International University
Islamabad
Email: [email protected]
Page 6 of 6