You are on page 1of 14

Practical-1

Q. To run following Linux commands: -

 Cal :- The ‘cal’ command print a calendar on the standard output.

Output: -

 Date :- date command displays/sets the system date and time.

Output: -

%D: Display date as mm/dd/yy.


%d: Display the day of the month (01 to 31).
%a: Displays the abbreviated name for weekdays (Sun to Sat).
%A: Displays full weekdays (Sunday to Saturday).
%h: Displays abbreviated month name (Jan to Dec).
%b: Displays abbreviated month name (Jan to Dec).
%B: Displays full month name(January to December).
%m: Displays the month of year (01 to 12).
%y: Displays last two digits of the year(00 to 99).
%Y: Display four-digit year.
%T: Display the time in 24 hour format as HH:MM:SS.
%H: Display the hour.
%M: Display the minute.
%S: Display the seconds.
 Who :- ‘who’ command shows information about users who are currently logged in.

Output: -

 Whoami :- ‘whoami’ prints the effective user ID. This command prints
the username associated with the current effective user ID.

Output: -

 Users :- ‘users’ command shows the user names of users currently logged in to the
current host.

Output: -
 Tput clear : It is used to clear the screen.

Output: -

 Ps :- ‘ps’ shows useful information about active processes running on a system.

Output: -

 Ls :- ‘ls’ command is used to list contents of a directory. It works more or less like dir
command.

Output: -

 ls –l :- The ‘ls-l’ option enables long listing format.


Output: -
 bc :- ‘bc’ is a simple yet powerful and arbitrary precision CLI calculator language
which can be used.

Output: -

 uname :- ‘uname’ command displays system information such as operating system,


network node hostname kernel name, version and release etc.

Output: -

 hostname :- ‘hostname’ command is used to print or set system hostname in Linux.

Output: -

 w :- ‘w’ command displays system uptime, load averages and information about the
users currently on the machine, and what they are doing (their processes).

Output: -
Practical-2
Q. To run following Linux commands: -

 echo :-‘ echo’ command prints a text of line provided to it.

Output: -

 printf :- “printf” command in Linux is used to display the given string, number or any
other format specifier on the terminal window.

Output: -

 info :- ‘info’ reads documentation in the info format. Info is similar to man, with a
more robust structure for linking pages together. Info pages are made using the
texinfo tools, and can link with other pages, create menus and ease navigation in
general.

$info mkdir
Output: -
 man :- ‘man’ command is used to view the on-line reference manual pages for
commands/programs like so.
$man ls

Output: -

 whatis :- ‘whatis’ command searches and shows a short or one-line manual page
descriptions of the provided command name(s)

Output: -

 help :- ‘help’ command just displays information about shell built-in commands.

Output: -
Practical-3
Q. To run following Linux commands: -

 cd :- ‘cd’ command in linux known as change directory command. It is used to


change current working directory.

Output: -

 mv :- ‘mv’ command is used to rename files or directories. It also moves a file or


directory to another location in the directory structure.

Output: -

 cp :- ‘cp’ command is used for copying files and directories from one location to
another.

Output: -

 rm :- ‘rm’ command is used to remove files or directories as shown below.

Output: -
 cat :- cat command is used to view contents of a file or concatenate files, or data
provided on standard input, and display it on the standard output.

Output: -
Practical-4
Q. Write a shell script to create arithmetic calculator.
echo "Enter first number"
read a
echo "Enter second number"
read b
echo "1.Addition"
echo "2.Subtraction"
echo "3.Division"
echo "4.Multiplication"
echo "Enter choice: "
read n
if [ $n -eq 1 ]
then
c=`expr $a + $b`
echo "Sum is $c "
fi

if [ $n -eq 2 ]
then
c=`expr $a - $b`
echo "Difference is $c "
fi

if [ $n -eq 3 ]
then
c=`expr $a / $b`
echo "Divide is $c "
fi
if [ $n -eq 4 ]
then
c=`expr $a \* $b`
echo "Product is $c "
fi

Output: -
Practical-5
Q. Write a shell script to print greatest of three numbers.
echo "Enter first number"
read a
echo "Enter second number"
read b
echo "Enter third number"
read c
if [ $a -gt $b -a $a -gt $c ]
then
echo "$a is greater"
elif [ $b -gt $a -a $b -gt $c ]
then
echo "$b is greater"
elif [ $c -gt $a -a $c -gt $b ]
then
echo "$b is greater"
else
echo "wrong input"
fi
Output: -
Practical-6
Q. Write a shell script to check whether a number is odd or even.
echo "Enter number"
read a
if [ $a % 2 -eq 0 ]
then
echo "$a is even"
else
echo "$a is odd"
fi
Output: -
Practical-7
Q. Write a shell script to check whether a number is prime or not.

echo "Enter number"


read number
i=2
f=0
while [ $i -le `expr $number / 2` ]
do
if [ `expr $number % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "Not Prime"
else
echo "Prime"
fi

Output: -

You might also like