unix presentation 6 (24 jan 08)
TRANSCRIPT
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
1/38
In the todays session well read :-
What is command
Option Arguments File Arguments
Internal and External commands
The Basic commands of UNIX
date
clear and tput banner who cal ls
cat Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
2/38
wc Feeding output of one command to another type path man uname tty
passwd lock echo cup smso and rmso bc Conti.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
3/38
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
4/38
What is a Command
The UNIX system is heavily command-based i.e. you have to
type in a few characters to frame a command and then press the
enter key for it to work.
UNIX commands are executable files and built-in utility
programs.
All UNIX commands are case sensitive. Most commands are in
lower case.
Commands typically have the syntax:
command option(s) argument(s)Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
5/38
Options :-
Modify the way that a command works.
Usually consist of a hyphen (-) followed by a single letter.
Some commands accept multiple options which can usuallybe grouped together after a single hyphen
A small number of commands require each option to begiven separately.
Should be separated from the command name by a space.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
6/38
Arguments :-
Most commands are used together with one or morearguments.
Some commands assume a default argument if none issupplied.
Arguments are optional for some commands and required byothers.
In most cases, multiple arguments should be separated fromeach other by a space. They should be separated from the
command name and/or options by a space also.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
7/38
FilenameArguments :- Many UNIX commands use a
filename as an argument so that the command can take input
from the file.
It is very general feature of the UNIX that some commandswork with more then one filename. For Ex.
$ ls -l chap01 chap02 chap03
The command with its arguments is entered in one line thatis referred to as the Command Line.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
8/38
Internal and External Commands
Files or programs that have independent existence in the /bin
directory (or /usr/bin) are branded as an External command.
Ex. ls (external command)
Most commands are external in nature, but there are some
which are not really found anywhere and some which are
normally not executed even if they are in one of the directories
specified by PATH. For Ex. echo command.
$ type echo
o/p : echo is a shell built-in.
Cont.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
9/38
echo is not a external command in the sense that, when you
type echo the system wont look in its PATH to locate it.
Rather, it will execute it from its own set of built-in
These built-in commands, of which echo is a member are
known as Internal commands.
The shell, which itself is a command, processes its own set of
commands and even if theres a command of the same name in
/bin or /usr/bin, the shell will record top priority to its own
internal command of the same name.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
10/38
The BasicCommands of UNIX
date (Display The System Date):- date command that
combines the functions of the DATE and TIME commands of
DOS.
The command does not prompt you to change eitherthe date or the time. This facility is only available tothe administrator and the strange thing is that he uses
the same command.
For Ex.
$ date
The command can also be used with suitable formatspecifiers as arguments.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
11/38
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
12/38
Conti.
There are other format specifier :
d day of the month (1 to 31)y last two digits of the year
H,M and S hour, minute and second respectively
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
13/38
clear and tput (Clear your Screen):- There are two
commands available in most UNIX systems to clear your
screen.
For Ex.$clear
If you get the message clear : not found on your
screen, try the other command tput which is the original
agent of the UNIX system
For Ex.
$ tput
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
14/38
tput requires some additional material to work properly. Toclear the screen, follow tput with the word clear
For Ex.
$ tput clear
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
15/38
banner (Display a Blown-Up Message) :- You can create
fancy objects on your screen with the banner command
For Ex.$ banner John lee
who (Login Details) :- The who command is there to tell you
who you are, so you should use it with two arguments am
and i :
$ who am I
If you want to see all user working on various terminalsthen simply write command.
For Ex. $ whoConti.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
16/38
For printing column headers write command
$ who Hu
-u option provides more detailed list
who is regularly used by the system administrator tomonitor weathers terminals are being properly utilized.
Conti.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
17/38
Conti.
cal :- cal is a handy tool that you can invoke any time to see
the calendar of any specific month or a complete year.
If you wish to see the calendar for the month of Decemberyou can provide this as an argument to cal :
$cal dec
$cal 1998 will print whole year moths. In this commandfor stop scrolling you have to use and
to resume it.
Instead of using for stop scrolling and toresume it we can also use this command :-
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
18/38
For Ex.
$cal 1998 | more
ls :- This command is used to list out the names of the files
available in current directory.
$ ls
If this command is showing 6 file with 3 file starting letterchap then we can also sort out these file by followingcommand :-
$ ls chap*
Conti.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
19/38
Conti.
For knowing some information about the list of files wecan use option with argument.
For ex.$ ls l chap*
Here (hyphen) is option
l is argument
cat (Displaying and createing files):- For showing contents
of any particular file
For Ex.
$cat filename Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
20/38
Unix has simple symbols (called operator) for creating andstoring information in file.
Instead of viewing the output of ls command on theterminal, we can save the information in the file list (file
name) using a
special symbol >
For Ex.
$ ls > filename(say list)
This mechanism is called redirecting any output normallycoming to the terminal to a disk file.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
21/38
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
22/38
-l option counts the number of lines :$ wc -l infile
-w option counts the number of words :$ wc -w infile
-c option counts the number of characters :$ wc -c infile
We can also count number of lines, words and characters ofmultiple files :
For Ex.
$ wc infile1 infile2 infile3
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
23/38
Conti.
Feeding output ofOne command to another :- This concept is
done by special symbol | (pipe)
For Ex.
$ ls | wc
will simply connecting the output of ls to the input of wc
type :- The best and fastest way to know the location of any
command in the UNIX inbuilt file system is type.
For Ex.
$ type ls
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
24/38
Path :- The sequence of directories that the system will search to
look for a command is specified in its own PATH variable. To
find a directory list separated by colons well write :
$ echo $PATH
man (On-line Help):- UNIX offers an on-line facility with the
man command.
For Ex. for help on the command wc you simply have to enter
$ man wc
Conti
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
25/38
-k :- The -k option accepts the keyword and man then givesyou the name and short description from all manual sections
that contain the keyword.
For Ex. :
$ man -k inode
Linux also offers - -help command
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
26/38
uname (Know Your Machines Name):- This command is used
to see version of UNIX OS. For Ex. :
$ uname -r
If your machine is connected to a network, then it must havea name. If your network is connected to the Internet, then
name is required to frame your machines domain name. The
uname command with the -n option tells you the machine
name in a network
For Ex.
$ uname -n
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
27/38
tty (Knowing Your Terminal):- Since UNIX treats even
terminals as files, it is reasonable to expect a command, an
obvious that tells you the filename of the terminal you are using.
It is the tty (teletype) command which tell you this thing. Itrequires no argument.
For Ex.
$ tty/dev/tty01
The terminal filename is tty01 resident in the /dev directory.
If sumit logs in from another terminal next time his terminaldevice name will be different.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
28/38
Changing Your Password
passwd (Change your Password) :- Your password is
important; it stops other users from gaining access to your
account. Never give your password to anyone.
You should change your initial password very soon after yourfirst login.
To change your password: enter the command passwd and then
respond to the prompts by entering your old password followed
by your new one. You are then asked to retype your password
for confirmation. Note that what you type will not appear onthe screen for security reasons.For example: $ passwdOld password: - enter your current password
New password: - enter your new passwordRet e new assword: - re-enter our new assword
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
29/38
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
30/38
Conti.
echo (Display Message) :- This command will print any
message given in its arguments
For Ex.
$ echo Sco Unix
O/P will be : Sco Unix
For Sco Unix output write command :$ echo Sco Unix
cup (Taming the Cursor) :- This command is used to position
the cursor at row number 10 and column 20
For Ex. : tput cup 10 20
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
31/38
smso :- This command is used for bold face your text by using
the smso and rmso.
For Ex.
$ tput smso$ echo Come to the Web
$ tput rmso
bc (The Calculator) :- This command is used as a calculator
For Ex.$ bc
For each calculation you have to press enter key and for
quitting from calculator press
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
32/38
Conti.
calendar :- The calendar command provides an useful
reminder mechanism for a user.
For Ex.
$cat calendar
The format mm-dd-yy or dd/mm/yy isnt recognized bycalendar as a valid date. Only mm/dd/yy is acceptable.
spell (Check your spelling) :- This command takes the nameof the file as a argument and generates a list of all spelling that
the program recognizes as mistake.
For Ex. :
$ spell linux.txt Conti
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
33/38
By default spelling are checked with reference to the USdictionary, but you can use the -b (British) option to use a
different one :
For Ex.
$ spell -b
Linux has ispell command.
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
34/38
Script (Record Your Session) :- All the commands, their
output and error messages are stored in the file for later
viewing. If you wish you stored all activities done by you then
you should write script command for recording.For Ex.
$ script
Script started, file is typescript
$_
For viewing contents of this file you have to exit from script
then type cat and typescript command on shell prompt.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
35/38
time (Timing Processes) :- When faced with several versions
of a program, it becomes necessary to find out drainage that the
command makes on the system resources. The time command
does this work.
It accepts the command to be timed as its argument and thennot only executes the program but displays the time usage in
the terminal as well.
This enables the programmer to tune their programs so thatCPU usage is kept at an optimum level.
For ex. You can find out the time taken to perform a sortingoperation by preceding the sort command. Conti
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
36/38
$ time sort -o a1
o/p : real 0m1.18s
user 0m0.73ssys 0m0.38s
The real time shown is the clock elapsed time from theinvocation of the command till its termination. The time can
differ on multi-user systems where several programs may be
running concurrently.
The user time shows the time spent by the program in
executing itself. Conti
Conti.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
37/38
Conti.
The sys time indicates the time used by the UNIX system indoing work on behalf of the user.
The sum of user time and system time actually represents theCPU time and its not necessary that this time be equal to the
real time or clock elapsed time (as you see in present case).
Since some time is consumed in doing other work in the
system. The more heavily loaded a system is the greater is the
difference.
-
8/7/2019 Unix Presentation 6 (24 Jan 08)
38/38
End ofChapter 1