Custom Search

Friday 18 May 2012

Unix command Cal, who, ps, ls, echo, meaning, Linux Function meaning of Cal, who, ps, ls, echo with example


Unix command Cal, who, ps, ls, echo, meaning, Linux Function meaning of Cal, who, ps, ls, echo with example


Cal:- It produces the calender of the month or year
for eg:-

$ cal 7 2012

answer is
July 2012
Su Mo Tu We Th Fr Sa
1   2     3    4    5   6   7
8   9   10  11  12  13 14
15 16 17  18 19   20 21
22 23 24  25  26  27 28
29 30 31

*******************************

who:- it shows the user working on the system & the time of loging in
For eg:-
$ who

answer is
nikun console June 12 12:01
nidhi   pts/4    June 12 12:04
jhon    pts/4    June 12 12:06

there are currently three users nikun, nidhi & jhon. These are actually the user-id or username they used to login. please note that who does not include any header like in ps command.
The second column i.e "console" shows the name of he terminal the user is working on

********************************

ps:- It displays the process running in the system
for eg:-

$ ps

PID TTY  Time CMD
496 ptsw 0:00 ksh
364 console 0:00 ksh
where PID is the process-id & ksh represents the korn shell
ps generates the header followed by a line containing the details of the process.
When you run several process, there will be multiple lines in the ps output

*********************************

ls:It command is used to list the names of all the files available in the directory. Files are organised in a separate folder called directories.


For eg:-
$ ls


MATHS
chap 12
chap 13
chap 14
chap 15
wordsdir
progs
lengthdir


***********************************


echo:- It displays the message on the screen. it can work with the escape sequence like /c & /t as well as octal number like \007.

Monday 14 May 2012

Linux shell script to accept two file names, if both files exist then contents of first file should appended to second. If second file does not exist then create it with the contents of first file, Unix Program to perform operation on file

Linux shell script to accept two file names, if both files exist then contents of first file should appended to second. If second file does not exist then create it with the contents of first file, Unix Program to perform operation on file



Program
clear


echo"Enter first file name:"
read f1
echo"Enter second file name:"
read f2


if test -f$f1


then
echo " File $f1 is already exist"
else
echo "File created successfully"
cat > $f1
fi
if test -f $f2
then
echo "File $f2 is already exist"
else
echo "File created successfully"
 cat > $f2
fi
cat < $f1>>$f2


Output


Enter first file name:tmp1.sh
Enter second file name:tmp2.sh
File tmp1 is already exist.
File tmp2 created successfully.
Note:All the content of tmp1 is copied to tmp2. 

Tuesday 8 May 2012

Write a Linux shell script which display full names like January if we enter janu, janua, and so on........, Unix Program for word prediction


Write a Linux shell script which display full names like January if we enter janu, janua, and so on........, Unix Program for word prediction 


Program
clear


echo"Enter initials of month:"
read mon


case $mon in
ja*)echo"Month is January.";;
f*)echo"Month is February.";;
mar*)echo"Month is March.";;
ap*)echo"Month is April.";;
may*)echo"Month is May.";;
jun*)echo"Month is June.";;
jul*)echo"Month is July.";;
au*)echo"Month is August.";;
s*)echo"Month is September.";;
o*)echo"Month is October.";;
n*)echo"Month is November.";;
d*)echo"Month is December.";;
*)echo"Invalid month.";;
esac


Output:
Enter initials of month: jan
Month is January.
<<< Previous  ||  Current  ||  Next >>>  

Write a Linux shell script that counts occurrence of a word in file, Unix program that counts occurrence of number of words in file


Write a Linux shell script that counts occurrence of a word in file, Unix program that counts occurrence of number of words in file


Program
clear


echo-n"Emter file name:"
read fn


echo-n"Enter the pattern:"
read pt


c='grep-io$pt$fn|wc-w'
echo" No.of occurrence:"$c


Output:
Enter file name:temp.sh
Enter the pattern: file
No.of occurrence:4
<<< Previous  ||  Current  ||  Next >>>  

Write a Linux shell script for comparison between two strings whether both the strings are equal or not, Unix program for comparison between two strings


Write a Linux shell script for comparison between two strings whether both the strings are equal or not, Unix program for comparison between two strings


Program
clear
echo"Enter String 1:"
read str1


echo"Enter String 2:"
read str2


s1='expr$str1|wc-c'
s1='expr$s1-1'


s2='expr$str2|wc-c'
s2='expr$s2-1'


flag=0


if[$s1-ne$s2]
then
 echo"Strings are different"
else
 for((i=1;i<=s1;i++))
 do
  sc1='expr$str1|cut-c$i'
  sc2='expr$str2|cut-c$i'


  if[$sc1!=$sc2]
  then
       flag=1
       break
  fi
 done


if[ $flag-eq 0]
then
  echo"String are equal"
else
 echo"Strings are different"
fi
fi


Output:
Enter string 1: Maulik
Enter string 2: Dantara
Strings are different.

<<< Previous  ||  Current  ||  Next >>>  

Laptops