0% found this document useful (0 votes)
0 views8 pages

Os 2

The document outlines practical exercises for executing general purpose commands in an operating system, including 'date', 'cal', 'clear', 'banner', 'tty', 'script', and 'man'. Each command is accompanied by its syntax, explanation, and examples of usage. The document concludes with a summary of the successful execution of these commands.

Uploaded by

Ketki Lodhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views8 pages

Os 2

The document outlines practical exercises for executing general purpose commands in an operating system, including 'date', 'cal', 'clear', 'banner', 'tty', 'script', and 'man'. Each command is accompanied by its syntax, explanation, and examples of usage. The document concludes with a summary of the successful execution of these commands.

Uploaded by

Ketki Lodhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

FC5462 - Operating System

Practical No. 2
Aim: Execute general purpose commands date & time, cal, clear, banner, tty,
script, man.

Theory:
Study the commands and execute the same for given commands.
Precaution: Follow the proper syntax of every command.

Table 1. Commands and their Syntax


Command Syntax Explanation
Clear clear Clears the screen.
Banner banner text Used to display a poster.
Date date Displays the the current date & time or changes
date format the system date & time to the specified value.
Cal cal[13smjy][month][year] Displays calendar of any specific month or a
cal format complete year.
Man man command-name Prints the specified man page.
Script script [options] [file] Record login session.
Tty tty [option] Prints the file name of the terminal connected to
standard input.

Theory:
Study the commands and execute the same for given commands.
Precaution: Follow the proper syntax of every command.

Examples:

1. clear
It clears the screen.
$ clear

Practical No. 2
FC5462 - Operating System

2. banner
This command displays its argument like poster, with maximum of 10
characters per line. Use quotes for your arguments to preserve formatting.
$ banner Hello
# # ##### # # #####
# # # # # # #
##### ### # # # #
# # # # # # #
# # ##### ##### ##### #####

The above output is just for a sample, the actual output may have more or
less Hash symbols.

3. date
Following command displays current date & time if no argument is
given.

$ date
Tue May 6 02:45:40 IST 2003
Formatted output for date command:
Field Descriptor Function
%a Abbreviated weekdays(SUN to SAT)
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Current date & time
%C Century (00 to 99)
%d Day of month 0 to 31
%D Day as MM/DD/YY
%e Day of month as decimal number
%h Abbreviated month
%H Hour 00 to 23
%I 01 to 12 (12 hour clock)
%j Day of the year 001 to 366
%m Month of the year 01 to 12
%M Minute 00 to 59
%n New time
%p AM/PM
%r Time in AM/PM notation
%T Time in hh:mm:ss (23 hrs clock)

Practical No. 2
FC5462 - Operating System

e.g. To display the date & time in the format


DATE=
TIME=
DAY=
Command is $ date ‘+DATE=%D%n TIME=%T%n DAY=%A’
To use multiple specifiers, enclose them within quotes and use + symbol
before it.
$ date +%m
05
$ date +”%h %d”
May 03

4. cal
It displays calendar of prev/current/next month if no argument is
specified.
Displays calendar of specific year if specified.
$ cal
Table 2.
Options Function
-1 Display single month output.
-3 Display prev/current/next month output.
-s Display Sunday as first day of week.
-m Display Monday as first day of week.
-j Display Julian dates.
-y Display a calendar for current year.

5. man
Specify the command name after man, it will display the man page of
that command.
$ man ls
Note: If output of a command is larger than one page, it can be redirected
to more or less command for slower display as shown below:
$ man ls | less

Practical No. 2
FC5462 - Operating System

6. script

script command in Linux is used to make typescript or record all the


terminal activities. After executing the script command it starts recording
everything printed on the screen including the inputs and outputs until exit.
By default, all the terminal information is saved in the file typescript , if no
argument is given. script is mostly used when we want to capture the output
of a command or a set of command while installing a program or the logs
generated on the terminal while compiling an opensource codes, etc. script
command uses two files i.e. one for the terminal output and other for the
timing information.

# cat shell_record1
Script started on Fri 09 Jun 2020 06:23:41 PM UTC
[root@centos-01 ~]# date
Fri Jun 9 18:23:46 UTC 2020
[root@centos-01 ~]# uname -a
Linux centos-01 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24
UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@centos-01 ~]# whoami
root
[root@centos-01 ~]# pwd
/root
[root@centos-01 ~]# exit
exit

Script done on Fri 09 Jun 2020 06:25:11 PM UTC

7. tty

The tty command of terminal basically prints the file name of the
terminal connected to standard input. tty is short of teletype, but

Practical No. 2
FC5462 - Operating System

popularly known as a terminal it allows you to interact with the system


by passing on the data (you input) to the system, and displaying the
output produced by the system.
$tty

/dev/pts/19

Note that the command produces a message like "not a tty" if it is not
running inside a terminal.

Practical No. 2
Exercise:

1. Execute and observe echo –E “Hello” command.

[Write commands for following tasks Q. 2 to 5]

2. Display day, month & year by using single date command.

3. Display seconds, minutes & hours of the day by using date command.

4. Display the calendar of current month by cal command.


5. Display the calendar of previous, current & next month simultaneously by
using cal.

6. Execute the command and write the output for cal 05 2020 command.
7. Execute the command & write the output for cal 02 command.

8. What happen if you type man man command? Comment.


man man command in Linux is used to display the user manual of any command that we can
run on terminal. It provides a detailed view of the command which includes NAME,
SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES,
VERSIONS, EXAMPLES, AUTHORS AND SEE ALSO.

Conclusion: Thus, we successfully executed general purpose commands date & time, cal,
clear, banner, tty, script, man.

You might also like