Full text

(1)

UNIX

Reference:

UNIX Concepts and Applications – 4th Edition

By

(2)

General Purpose Utilities

• cal : The calendar

• date : Displaying the system date

• echo : Displaying a message

• printf : An alternative to echo

• bc : The calculator

• script : Recording your session

(3)

General Purpose Utilities

• passwd : Changing your password

• who : Who are the users

• uname : Knowing your machine’s characteristics

• tty : Knowing your terminal

(4)

cal : The calendar

• Syntax drawn from Solaris man page

cal [ [ month ] year ]

• Everything within rectangular brackets is optional

cal without arguments displays the calendar

of the current month

(5)

cal : The calendar

• To see the calendar for the month of September 2014 we need two arguments

(6)

cal : The calendar

• We can not hold the calendar of a year in a single screen page. To do that i.e. to stop the scrolling

$ cal 2014 | more

(7)

date : Displaying the system date

• The UNIX system maintains an internal clock

meant to run perpetually.

• When the system is shut down, a battery backup keeps the clock ticking.

(8)

date : Displaying the system date

• A 32 bit counter stores these seconds (except

(9)

date : Displaying the system date

We can display the current date with date

command.

$ date

(10)

date : Displaying the system date

• The command can also be used with suitable

format specifiers as arguments.

• To print only the month we use

$ date +%m 08

• To print the month name we use

(11)

date : Displaying the system date

• To combine the above two we use

(12)

date : Displaying the system date

There are many other format specifiers e.g.

• d – the day of the month (1 to 31)

• y – the last two digits of the year

• H, M, and S – the hour, minute and second, respectively

• D – the date in the format of mm/dd/yy

(13)

echo : Displaying a message

$ echo Hello Dipankar Hello Dipankar

(14)

echo : Displaying a message

• Originally echo was an external command, but today all the shells have echo built in.

(15)

echo : Displaying a message

(16)

echo : Displaying a message

Some escape sequences

• \a Bell

• \b Backspace

• \c No newline

• \n Newline

• \r Carriage return

(17)

printf : An alternative to echo

$ printf “No filename entered \n” No filename entered

(18)

bc : The calculator

• The UNIX provides a calculator –the text based bc command.

• bc is less friendly, extremely powerful

$ bc 12 + 5 17

[ctrl d]

(19)

bc : The calculator

$ bc

12 * 5 ; 2^32 144

4294967296

[ctrl d]

(20)

bc : The calculator

• bc performs only integer computation and truncates the decimal portion that it sees.

$ bc 9/5 1

[ctrl d]

(21)

bc : The calculator

• To enable floating point computation, we have to set the scale to the number of digits of precision.

$ bc

scale=2 17/7

2.42

[ctrl d]

(22)

bc : The calculator

• bc is quite useful in converting numbers from one base to another.

$ bc

ibase=2

1111 input binary

(23)

bc : The calculator

• bc is quite useful in converting numbers from one base to another.

$ bc

obase=2

15 input decimal

(24)

script : Recording your session

• This command lets you “record” your login session in a file.

• You can letter view the file.

$ script

script started, file is typescript $_

(25)

script : Recording your session

• After the recording is over, you can terminate the session by –

$ exit

Script done, file is typescript $_

(26)

script : Recording your session

script overwrites any previous typescript that

may exist.

• If you want to append to it then

$ script –a

• If you want to use a different log file then

(27)

script : Recording your session

(28)

mailx : The universal mailer

mailx a character based mail agent

mailx finds place in the POSIX specification,

which no longer requires UNIX systems to support the earliest mail agent of all – the mail command.

(29)

mailx : The universal mailer

There are two ways of invoking mailx – in the sending and receiving modes.

In the sending mode mailx is used with the email address of the recipient as argument.

(30)

mailx : The universal mailer

Sending mail from user DD to PC

$ mailx PC

Subject: New system

New system will start functioning from next month.

(31)

mailx : The universal mailer

Receiving mail

All incoming mail is appended to the mailbox. This is a text file named after user-id of the recipient. UNIX system maintain the mailbox in a directory which is usually /var/mail.

(32)

mailx : The universal mailer

Receiving mail

By default mailx reads this file for viewing received mail.

(33)

passwd : Changing your password

To change your password:

$ passwd

Old password: enter your current password New password: enter your new password

(34)

passwd : Changing your password

Enter the command passwd and then respond

to the prompts by entering your old password followed by your new one.

(35)

passwd : Changing your password

• If you make a mistake, the message

Mismatch - password unchanged.

(36)

passwd : Changing your password

• When you enter a password, the string is

encrypted by the system.

• This encryption is stored in a file named

shadow in the /etc directory.

(37)

who : Who are the users

To find out who is logged on to the system:

$ who

erco02 ttyPt Nov 3 08:01 (braid.ucs:0.0)

fran ttyPu Oct 26 11:23 (dirac.maths.ed.a)

calvin ttyPv Nov 5 09:07 (hobbes.ucs.ed.ac)

djs ttyPx Nov 5 11:39 (129.215.72.75)

aipex ttyPB Nov 5 11:41 (owl.dai.ed.ac.uk)

harvey ttyPF Nov 5 09:12 (rabbit.warren.ed)

(38)

who : Who are the users

• To find out who is logged on and prevent the information from rolling off the screen:

(39)

who : Who are the users

who - show who is logged on

SYNOPSIS

(40)

who : Who are the users

DESCRIPTION

-a, --all

-b, --boot time of last system boot

-H, --heading print line of column headings -l, --login print system login processes

(41)

who : Who are the users

DESCRIPTION

-q, --count all login names and number of users logged on

-r, --runlevel print current runlevel

-s, --short print only name, line, and time (default)

(42)

uname : Knowing your machine’s

characteristics

uname - print name of current system

SYNOPSIS

uname [-aimnprsvX]

(43)

uname : Knowing your machine’s

characteristics

DESCRIPTION

• The uname utility prints information about the current system on the standard output.

• When options are specified, symbols representing one or more system characteristics will be written to the standard output.

(44)

uname : Knowing your machine’s

characteristics

OPTIONS

-a Prints basic information currently available from the system.

-i Prints the name of the platform.

(45)

uname : Knowing your machine’s

characteristics

OPTIONS

-n Prints the nodename (the nodename is the name by which the system is known to a

communications network).

-p Prints the current host's ISA or processor type.

-r Prints the operating system release level.

(46)

tty : Knowing your terminal

• UNIX treats even terminal as files.

• tty displays the device name of your terminal.

$ tty

(47)

tty : Knowing your terminal

• The terminal filename is 10 (a file named 10) resident in the pts directory.

This directory in turn is under the /dev directory.

(48)

stty : Displaying and setting

terminal characteristics

• Different terminals have different characteristics, and your terminal may not behave in the way you expect it to.

(49)

stty : Displaying and setting

terminal characteristics

stty displays and sets various terminal

attributes.

• We can define the key that interrupts a program and marks end of file.

$ stty –a

Figure

Updating...

References

Related subjects :