Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 38

In the today’s session we’ll 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….
Conti….

• wc
• Feeding output of one command to another
• type
• path
• man
• uname
• tty
• passwd
• lock
• echo
• cup
• smso and rmso
• bc Conti….
Conti….

• calendar
• spell
• script
• time
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….
Conti….

 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 usually
be grouped together after a single hyphen

• A small number of commands require each option to be


given separately.

• Should be separated from the command name by a space.


Conti….

 Arguments :-
• Most commands are used together with one or more
arguments.

• Some commands assume a default argument if none is


supplied.

• Arguments are optional for some commands and required


by
others.

• In most cases, multiple arguments should be separated from


each other by a space. They should be separated from the
command name and/or options by a space also.
Conti….

 Filename Arguments :- 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 commands


work with more then one filename. For Ex.

$ ls -l chap01 chap02 chap03

• The command with its arguments is entered in one line that


is referred to as the Command Line.
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….
 echo is not a external command in the sense that, when you
type echo the system won’t 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 there’s 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.
The Basic Commands 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 either
the date or the time. This facility is only available to
the administrator and the strange thing is that he uses
the same command.
For Ex.
$ date

• The command can also be used with suitable format


specifiers as arguments.
Conti….
• Each format is preceded by a + symbol, followed by
% operator and single character describing the
format.

• For Ex. You can print only the month, using the
format +%m
$ date +%m

Or month name by following command :

$ date +%h

We can also combine them like :


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
 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….
Conti….

• tput requires some additional material to work properly.


To clear the screen, follow tput with the word “clear”

For Ex.

$ tput clear
Conti….

 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 terminals
then simply write command.
For Ex. $ who
Conti….

• For printing column headers write command

$ who –Hu

-u option provides more detailed list

• who is regularly used by the system administrator to


monitor weathers terminals are being properly utilized.

Conti….
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 December


you can provide this as an argument to cal :

$ cal dec

• $ cal 1998 will print whole year moths. In this command


for stop scrolling you have to use <Ctrl -s> and <Ctrl-q>
to resume it.

• Instead of using <Ctrl-s> for stop scrolling and <Ctrl-q>


Conti….

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 letter


chap then we can also sort out these file by following
command :-

$ ls chap*
Conti….

• For knowing some information about the list of files we


can 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….

• Unix has simple symbols (called operator) for creating and


storing information in file.

• Instead of viewing the output of ls command on the


terminal, 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 normally


coming to the terminal to a disk file.
Conti….

• Now you can see the contents of list file by

$ cat list

 wc :- This command is used to count number of line, words and


character in file

For Ex.
$ wc list
will give you above result.
Conti….

• -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 of


multiple files :
For Ex.
$ wc infile1 infile2 infile3
Conti….

 Feeding output of One 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
 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 we’ll 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…
Conti….

• -k :- The -k option accepts the keyword and man then gives


you the name and short description from all manual sections
that contain the keyword.

For Ex. :

$ man -k inode

Linux also offers - -help command


Conti….

 uname (Know Your Machine’s 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 have


a name. If your network is connected to the Internet, then
name is required to frame your machine’s domain name. The
uname command with the -n option tells you the machine
name in a network
• For Ex.

$ uname -n
Conti….

 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. It


requires 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 terminal
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 your
first 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 on
the screen for security reasons.
For example: $ passwd
Old password: - enter your current password
New password: - enter your new password
Retype new password: - re-enter your new password
Conti….

 lock (Lock your Terminal) :- You sometimes need to be


away your terminal for a while and don’t want to log out
because a job is running in the background. This is done with
the lock command, which requires you to enter a password
when you decide to lock it. For Ex. :
$ lock
Password :*****
Re-enter Password : *****
terminal locked by sumit 0 minute ago
It will lock for 30 minutes

• You may decide to set the duration of the lock by using an


option : $ lock -45
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
Conti….

 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 <Ctrl-d>
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 isn’t recognized by


calendar as a valid date. Only mm/dd/yy is acceptable.

 spell (Check your spelling) :- This command takes the name


of the file as a argument and generates a list of all spelling that
the program recognizes as mistake.

For Ex. :
$ spell linux.txt Conti…
Conti….

• By default spelling are checked with reference to the US


dictionary, but you can use the -b (British) option to use a
different one :
For Ex.

$ spell -b

Linux has ispell command.


 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.
 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 then


not only executes the program but displays the time usage in

the terminal as well.

• This enables the programmer to tune their programs so that


CPU usage is kept at an optimum level.

• For ex. You can find out the time taken to perform a sorting
Conti….

$ time sort -o a1

o/p : real 0m1.18s


user 0m0.73s
sys 0m0.38s

• The real time shown is the clock elapsed time from the
invocation 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


Conti….

• The sys time indicates the time used by the UNIX system in
doing work on behalf of the user.

The sum of user time and system time actually represents the
CPU 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.
End of Chapter 1

You might also like