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

OSY Practical Assignment No.2

The document discusses different options for the cal and date commands in Linux/Unix. It provides examples of using cal to display calendars for specific months and years. It also covers using date to output dates in different formats and displaying the current day of the week. Practical questions are included about recording terminal sessions and displaying calendars.

Uploaded by

krish
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)
60 views

OSY Practical Assignment No.2

The document discusses different options for the cal and date commands in Linux/Unix. It provides examples of using cal to display calendars for specific months and years. It also covers using date to output dates in different formats and displaying the current day of the week. Practical questions are included about recording terminal sessions and displaying calendars.

Uploaded by

krish
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/ 9

PROGRAM CODE :

1. Write down different options for cal commands. (use $man cal)
Ans.
-h : Turns of highlighting of today.

-J : Display Julian Calendar, if combined with the

–o option, display date of Orthodox Easter according to the Julian Calendar.

-e : Display date of Easter (for western churches).

-j : Display Julian days (days one-based, numbered from January 1).

-m month : Display the specified month. If month is specified as a decimal


number, appending ‗f‘ or ‗p‘ displays the same month of the following or
previous year respectively.

-o : Display date of Orthodox Easter (Greek and Russian Orthodox


Churches).

-p : Print the country codes and switching days from Julian to Gregorian
Calendar as they are assumed by ncal. The country code as determined from
the local environment is marked with an asterisk.

-s country_code : Assume the switch from Julian to Gregorian Calendar at


the date associated with the country_code. If not specified, ncal tries to
guess the switch date from the local environment or falls back to September
2, 1752. This was when Great Britain and her colonies switched to the
Gregorian Calendar. -w : Print the number of the week below each week
column.

-y : Display a calendar for the specified year. This option is implied when a
year but no month are specified on the command line.

-3 : Display the previous, current and next month surrounding today.

-1 : Display only the current month. This is the default.


-A number : Months to add after. The specified number of months is added
to the end of the display. This is in addition to any date range selected by the
-y, -3, or -1 options. For example, ―cal -y -B2 -A2‖ shows everything from
November of the previous year to February of the following year. Negative
numbers are allowed, in which case the specified number of months is sub‐
tracted. For example, ―cal -y -B-6‖ shows July to December. And ―cal -
A11‖ simply shows the next 12 months.

-B : Months to add before. The specified number of months is added to the


beginning of the display. See -A for examples.

-C : Completely switch to cal mode. For cal like output only, use -b instead.

-N : Switch to ncal mode.

-d yyyy-mm : Use yyyy-mm as the current date (for debugging of date


selection).

-H yyyy-mm-dd : Use yyyy-mm-dd as the current date (for debugging of


highlighting).

-M : Weeks start on Monday.

-S : Weeks start on Sunday.

-b : Use old style format for ncal output.

2. Write options of date command.(Use $man date).


Ans.
-d, --date=STRING : display time described by STRING, not 'now' --debug :
annotate the parsed date, and warn about questionable usage to stderr

-f, --file=DATEFILE : like --date; once for each line of DATEFILE

-I[FMT], --iso-8601[=FMT] : output date/time in ISO 8601 format.


FMT='date' for date only (the default), 'hours', 'minutes', 'seconds', or 'ns' for
date and time to the indicated precision. Example: 2006-08-14T02:34:56-
06:00
-R, --rfc-email : output date and time in RFC 5322 format. Example: Mon,
14 Aug 2006 02:34:56 -0600

--rfc-3339=FMT : output date/time in RFC 3339 format. FMT='date',


'seconds', or 'ns' for date and time to the indicated precision. Example: 2006-
08-14 02:34:5606:00
-r, --reference=FILE : display the last modification time of FILE

-s, --set=STRING : set time described by STRING

-u, --utc, --universal : print or set Coordinated Universal Time (UTC)

--help : display this help and exit

--version : output version information and exit

PRACTICAL RELATED QUESTIONS :

1) How you record all the activities performed by the user.


Ans.
Script command is used to record all the terminal activities. By default all
the information is saved in file typescript. And to stop the typescript exit
command is used. Syntax: script [options] [file]

2) Give a command to display calendar for month of January.


Ans.
 While the cal/ncal commands display the current month by default, you
can use the - m command-line option in order to have a specific month
displayed.
 This option requires a numeric value (1-12) that represents the month you
want the command to display.
 To display the month of January of current year: cal -m1
 To display calendar of specific month and year: cal [ [month] year].

3) Give a single command to display the calendar of pervious, current and next
month.
Ans.
cal -3 command is used to display the calendar of pervious, current and next
month.

4) Give the command to display full week day (eg. Sunday) using date
command.
Ans.
%A is used as Locale‘s abbreviated full weekday name (e.g., Sunday)

EXERCISE :

1) What is the output of the following commands?

Ans:

a) $cal 04 2019
b) $date ―+Today‘s information: %D and %B‖;cal

c) $date “+My clock is showing %H hours, %M minutes and %S seconds”

d) $cal -3
e) $cal -5

f) $cal -2000

2) Give the syntax of commands for displaying the output. (use date)
Ans.

a) This is ………. Month of the year ………. (Abbreviation for the month
and 4-digit year)
Ans. date “+This is %b month of the year %Y”
b) This is the ………. th day of this year.

Ans. date “+This is %j th day of this year”

CONCLUSION :
We successfully implemented commands to perform operations using
commands like date, time, cal, clear, banner , tty, script, man.

You might also like