SlideShare a Scribd company logo
#Lab1a
echo The arguments are
echo $*
echo "The arguments are in the reverse order";
n=$#
while [ $n -gt 0 ]
do
eval "echo $$n" #by using $ we are hiding special meaning of $
n=`expr $n - 1`
done
#/*user@user-Inspiron-N5050:~$ sh lab1a.sh a b c
#The arguments are
#a b c
#The arguments are in the reverse order
#c
#b
#a
#user@user-Inspiron-N5050:~$ sh lab1a.sh 1 2 3
#The arguments are
#1 2 3
#The arguments are in the reverse order
#3
#2
#1
#user@user-Inspiron-N5050:~$
#"Write a shell script that accepts two file names as arguments, check if the permissions for these
files are identical and if the permission are identical, output common permissions and otherwise
output each file name followed by its permissions."
#lab1b
if [ -e $1 ]
then
if [ -e $2 ]
then
x=`ls -l $1|cut -d " " -f1`
y=`ls -l $2|cut -d " " -f1`
if [ $x = $y ]
then
echo "common permission $x"
else
echo "diffrent permissons"
echo "filename is $1 permisson is $x"
echo "filename is $2 permisson is $y"
fi
else
echo "$2 not existing"
fi
else
echo "$1 not existing"
fi
#mit@mit-desktop:~$ gedit lab1b.sh
#mit@mit-desktop:~$ sh lab1b.sh 1 abc /* here abc is a file that not present in our system */
#abc not existing
#mit@mit-desktop:~$ sh lab1b.sh abc 1 /* here abc is a file that not present in our system */
#abc not existing
#mit@mit-desktop:~$ sh lab1b.sh 1 programme2 /* here programme2 is a file that not present in
our system */
#programme2 not existing
#mit@mit-desktop:~$
#"This programme i.e., lab 2 b is written by Ashok"
#write a shell script that accepts a path name & creates all the components in that path name as
directories.
#For ex, if the script is named mpc, then the command mpc a/b/c/d should create directories a, a/b,
a/b/c, a/b/c/d
echo $1>f1 #echo $1 holds the contents of file f1.
x=`cat f1|tr "/" " "`
for i in $x #$x holds all the command line arguments.
do
mkdir $i
cd $i
done
CONCEPT LAB3A
ADDING A USER
mit@mit-desktop:~$ adduser ashok #if this not work try below command.
mit@mit-desktop:~$ sudo adduser ashok
#this command is used to add user. Here sudo stands
for super user.
DISPLAYS PASSWORD FILE OF THE UNIX SYSTEM
mit@mit-desktop:~$ cat /etc/passwd
#this command is used to password file
of the unix system.
mit:x:1000:1000:mit,,,,:/home/mit:/bin/bash
#mit is user and he as password.
ashok:x:1002:1006:Ashok,,,:/home/ashok:/bin/bash #mit is user and he as password.
UNDERSTANDING GREP COMMAND
mit@mit-desktop:~$ cat > file1
mit ashok mca 1st sem
mit@mit-desktop:~$ grep "1st" file1
mit ashok mca 1st sem
mit@mit-desktop:~$ cat > file2
mitashokmca1stsem
mit@mit-desktop:~$ grep "1st" file2 #grep command is used to search the word "1st" is present or
not.
mitashokmca1stsem
mit@mit-desktop:~$ grep -w "1st" file2 #-w command searches the word iff the contents of the
file separated by spaces.
mit@mit-desktop:~$ grep -w "1st" file1
mit ashok mca 1st sem
mit@mit-desktop:~$ grep -c "1st" file1
1

#-c is used to count the number of occurence of the
given word ex: here 1st is occured for 1 time.

mit@mit-desktop:~$ grep -n "1st" file1 #-n is used to display in which line the word "1st" is
occured
1:mit ashok mca 1st sem
#lab3a
#write a shell scripts which accepts valid login name as arguments and prints corresponding home
directory,if no argument is specified print a sutiable error msg.
if [ $# -ne 0 ]
then
for i in $*
do
grep -w "$i" /etc/passwd>ash1#ash1 is a file if $i is present in a file /etc/passwd, the
line of the contents written in file "ash1" otherwise not.
if [ -s ash1 ]

#-s checks the file size.

then
echo "$i is valid user";

#if the file size is not zero then this statement
get exexuted.

cat ash1 | cut -d ":" -f6
else
echo "$i is not a valid user"; #if the file size is zero, this is executed.
fi
done
else
echo "no arguments are passed";
fi
#mit@mit-desktop:~$ sh ashu.sh mit
#mit is valid user
#/home/mit
#mit@mit-desktop:~$ sh ashu.sh MIT
#MIT is not a valid user
#mit@mit-desktop:~$ sh ashu.sh Mit
#Mit is not a valid user
#mit@mit-desktop:~$ sh ashu.sh ashok
#ashok is valid user
#/home/ashok
#mit@mit-desktop:~$ sh ashu.sh vinay
#vinay is not a valid user
#mit@mit-desktop:~$ sh ashu.sh #command with out any arguments.
#no arguments are passed
#Write a shell script OR Create a shell script file called File properties that read
#file name entered & out put it's permissions.
#LAB4A
x=1
while [ $x -eq 1 ]
do
echo "enter u r choice";
read ch
echo "u r choice is $ch"
case $ch in #$ch contain some value.
1 ) echo "file permission `ls -l $0|cut -d ' ' -f1`";; # -f1 is first fild & $0 is current file
itself .
2 )echo "link info `ls -l $0|cut -d ' ' -f2`";; #-f2 is 2nd field
3 )echo "owner info `ls -l $0|cut -d ' ' -f3`";;
4 )echo "group info `ls -l $0|cut -d ' ' -f4`";;
5 )echo "file size `ls -l $0|cut -d ' ' -f5`";;
6 )echo "date of creation `ls -l $0|cut -d ' ' -f6`";;
7 )echo "time `ls -l $0|cut -d ' ' -f7`";;
8 )echo "file name `ls -l $0|cut -d ' ' -f8`";;
* )echo "invald option"
esac
echo "Do you want to contine yes=1 or not=0";
read x
done
#WAP To Find Smallest Of 3 Numbers.
#lab6b
read a
read b
read c
small=$a
if [ $b -lt $a ]
then
small=$b
fi
if [ $c -lt $b ]
then
small=$c
fi
echo "$small is smallest number among $a $b & $c"
#ashok@ubuntu:~$ sh small.sh
#1
#2
#3
#1 is smallest number among 1 2 & 3
#ashok@ubuntu:~$ sh small.sh
#99
#2
#55
#2 is smallest number among 99 2 & 55
#ashok@ubuntu:~$ sh small.sh
#99
#1058
#-99
#-99 is smallest number among 99 1058 & -99
#ashok@ubuntu:~$
CONCEPT LAB7B
#WAS Script To Understand Argument Variables $0, $1, $2, $3, $* And $#
echo "Programme Name $0"
echo "1st Argument $1"
echo "2nd Argument $2"
echo "3rd Argument $3"
echo "All Arguments $*"
echo "Total No. Of Arguments $#"
#output
#ashok@ubuntu:~$ sh 7a.sh 1 2 3 4
#Programme Name 7a.sh
#1st Argument 1
#2nd Argument 2
#3rd Argument 3
#All Arguments 1 2 3 4
#Total No. Of Arguments 4
#ashok@ubuntu:~$
#Write A Shell Script to Compute The Sum Of Numbers Passed To It As Arguments On Command
Line And Display The Result.
#lab7b
num=$1
sum=0
a=0
while [ $num -ne 0 ]
do
rem=`expr $num % 10`
num=`expr $num / 10`
sum=`expr $sum + $rem`
done
echo "sum of digits is = $sum"
#output
#ashok@ubuntu:~$ sh 7b.sh 123
#sum of digits is = 6
#ashok@ubuntu:~$ sh 7b.sh 123456789
#sum of digits is = 45
#ashok@ubuntu:~$ sh 7b.sh 222222
#sum of digits is = 12
#ashok@ubuntu:~$
#Line1 $1 holds 1st Argument. num holds value of $1
#write a shell script that accept a list of filenames as its arguments, count and report occurence of
each word that is present
#in the first argument file on other argument files.
#lab9b
for pattren in `cat $1`
#file is variable like "i" for ex in lab2b programme.
do
for file in $*
#file is variable like "i" for ex in lab2b programme.
do
if [ $file != $1 ]
then
x=`grep -iow $pattren $file|wc -l`
echo "$file contains the word $pattren $x timesn"
fi
done
done
#mcaexam@mit:~$ sh lab9b.sh l1 l2 l3
#l2 contains the word abc 2 times
#
#l3 contains the word abc 2 times
#
#l2 contains the word abcd 1 times
#
#l3 contains the word abcd 1 times
#
#mcaexam@mit:~$ gedit lab9b.sh
#mcaexam@mit:~$ cat l1
#abc
#abcd
#mcaexam@mit:~$ cat l2
#abc
#abc
#abcd
#mcaexam@mit:~$ cat l3
#abc abc
#abcd
#mcaexam@mit:~$
#Lab5b.sh
if [ $# -lt 1 ]
then
echo "Enter file name as an argument";
else
for i in $*
do
if [ -e $i ]
then
x=`ls -l $i|cut -d " " -f7`
echo "file is $i and creation time is $x";
else
echo "$i doesn't exist";
fi
done
fi
#user@user-Inspiron-N5050:~$ sh lab5b.sh f1
#f1 doesn't exist
#user@user-Inspiron-N5050:~$ sh lab5b.sh lab5b.sh
#file is lab5b.sh and creation time is 18:52
#user@user-Inspiron-N5050:~$
#delete a word
#lab 8b
echo "enter a word"
read word
for i in $*
do
grep -iwv "$word" $i > temp
cat temp > $i
done
#user@user-Inspiron-N5050:~$ cat f1
#Ashok
#Harish
#Prakash
#user@user-Inspiron-N5050:~$ cat f2
#inay
#Ashok
#Mahendra
#user@user-Inspiron-N5050:~$ sh lab8b.sh f1 f2
#enter a word
#Ashok
#user@user-Inspiron-N5050:~$ cat f1
#Harish
#Prakash
#user@user-Inspiron-N5050:~$ cat f2
#inay
#Mahendra
#user@user-Inspiron-N5050:~$
#labb11b.sh
if [ $3 -ge $2 ]
then
n=`cat $1|wc -l`
if [ $n -ge $3 ]
then
x=`expr $3 - 1`
y=`expr $x - $2`
head -$x $1|tail -$y
else
echo "insufficient number of lines";
fi
else
echo "ending line number should be greater than starting line number ";
fi
#user@user-Inspiron-N5050:~$ cat f1
#hari
#ashok
#prasad
#prakash
#mary
#koppal
#udupi
#ubuntu
#unix
#windows
#user@user-Inspiron-N5050:~$ sh labb11b.sh f1 2 6
#prasad
#prakash
#mary
#user@user-Inspiron-N5050:~$
#lab11a.sh
k=$2
if [ $k -lt 0 ]
then
k=`expr $k * -1`
fi
i=$1
j=1
pow=1
while [ $j -le $k ]
do
pow=`expr $pow * $i`
j=`expr $j + 1`
done
if [ $2 -lt 0 ]
then
echo "scale=3;`expr 1/$pow`"|bc
else
echo "$1 to the power of $2 is $pow"
fi

#user@user-Inspiron-N5050:~$ sh lab11a.sh 2 3
#2 to the power of 3 is 8
#user@user-Inspiron-N5050:~$ sh lab11a.sh 2 -3
#.125
#user@user-Inspiron-N5050:~$

More Related Content

What's hot

Lisp
LispLisp
Input output redirection linux
Input output redirection linuxInput output redirection linux
Input output redirection linux
Tanishq Soni
 
Unix - An Introduction
Unix - An IntroductionUnix - An Introduction
Unix - An Introduction
Deepanshu Gahlaut
 
Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)
Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)
Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)
Mansi Tyagi
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
Jussi Pohjolainen
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
FellowBuddy.com
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
Fatima Qayyum
 
Von neumann Architecture | Computer Science
Von neumann Architecture | Computer ScienceVon neumann Architecture | Computer Science
Von neumann Architecture | Computer Science
Transweb Global Inc
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
Akila Krishnamoorthy
 
Rabin Carp String Matching algorithm
Rabin Carp String Matching  algorithmRabin Carp String Matching  algorithm
Rabin Carp String Matching algorithm
sabiya sabiya
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
Kumar Pritam
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation process
Rahul Jamwal
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
Danish Javed
 
File organisation
File organisationFile organisation
File organisation
Suneel Dogra
 
Purpose of command interpreter
Purpose of command interpreterPurpose of command interpreter
Purpose of command interpreter
Sumant Diwakar
 
Big omega
Big omegaBig omega
Big omega
Rajesh K Shukla
 
Operating System Structure
Operating System StructureOperating System Structure
Operating System Structure
Navid Daneshvaran
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
Harshith Meela
 

What's hot (20)

Lisp
LispLisp
Lisp
 
Input output redirection linux
Input output redirection linuxInput output redirection linux
Input output redirection linux
 
Unix - An Introduction
Unix - An IntroductionUnix - An Introduction
Unix - An Introduction
 
Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)
Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)
Problem solving UNIT - 4 [C PROGRAMMING] (BCA I SEM)
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 
Von neumann Architecture | Computer Science
Von neumann Architecture | Computer ScienceVon neumann Architecture | Computer Science
Von neumann Architecture | Computer Science
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Rabin Carp String Matching algorithm
Rabin Carp String Matching  algorithmRabin Carp String Matching  algorithm
Rabin Carp String Matching algorithm
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
C++ compilation process
C++ compilation processC++ compilation process
C++ compilation process
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
 
File organisation
File organisationFile organisation
File organisation
 
Purpose of command interpreter
Purpose of command interpreterPurpose of command interpreter
Purpose of command interpreter
 
Big omega
Big omegaBig omega
Big omega
 
Operating System Structure
Operating System StructureOperating System Structure
Operating System Structure
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 

Similar to Unix 1st sem lab programs a - VTU Karnataka

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
mugeshmsd5
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Coming Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsComing Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix Shells
Kel Cecil
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
Raghu nath
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
Dr.M.Karthika parthasarathy
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
Dr.Ravi
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
tutorialsruby
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
Ben Pope
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
Advanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptAdvanced linux chapter ix-shell script
Advanced linux chapter ix-shell script
Eliezer Moraes
 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
Gaurav Shinde
 
Bash shell
Bash shellBash shell
Bash shell
xylas121
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
Brahma Killampalli
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Ashrith Mekala
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
plarsen67
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
Tushar B Kute
 

Similar to Unix 1st sem lab programs a - VTU Karnataka (20)

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Coming Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix ShellsComing Out Of Your Shell - A Comparison of *Nix Shells
Coming Out Of Your Shell - A Comparison of *Nix Shells
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Advanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptAdvanced linux chapter ix-shell script
Advanced linux chapter ix-shell script
 
Shell programming
Shell programmingShell programming
Shell programming
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Bash shell
Bash shellBash shell
Bash shell
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 

More from iCreateWorld

Unix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU KarnatakaUnix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU Karnataka
iCreateWorld
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
iCreateWorld
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
iCreateWorld
 
Data structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsData structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU Exams
iCreateWorld
 
Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.
iCreateWorld
 
1 location tracking of android device based on sms
 1 location tracking of android device based on sms 1 location tracking of android device based on sms
1 location tracking of android device based on sms
iCreateWorld
 

More from iCreateWorld (6)

Unix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU KarnatakaUnix 1st sem lab programs b - VTU Karnataka
Unix 1st sem lab programs b - VTU Karnataka
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
Data structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU ExamsData structure singly linked list programs VTU Exams
Data structure singly linked list programs VTU Exams
 
Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.Location Tracking of Android Device Based on SMS.
Location Tracking of Android Device Based on SMS.
 
1 location tracking of android device based on sms
 1 location tracking of android device based on sms 1 location tracking of android device based on sms
1 location tracking of android device based on sms
 

Recently uploaded

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 

Recently uploaded (20)

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 

Unix 1st sem lab programs a - VTU Karnataka

  • 1. #Lab1a echo The arguments are echo $* echo "The arguments are in the reverse order"; n=$# while [ $n -gt 0 ] do eval "echo $$n" #by using $ we are hiding special meaning of $ n=`expr $n - 1` done #/*user@user-Inspiron-N5050:~$ sh lab1a.sh a b c #The arguments are #a b c #The arguments are in the reverse order #c #b #a #user@user-Inspiron-N5050:~$ sh lab1a.sh 1 2 3 #The arguments are #1 2 3 #The arguments are in the reverse order #3 #2 #1 #user@user-Inspiron-N5050:~$
  • 2. #"Write a shell script that accepts two file names as arguments, check if the permissions for these files are identical and if the permission are identical, output common permissions and otherwise output each file name followed by its permissions." #lab1b if [ -e $1 ] then if [ -e $2 ] then x=`ls -l $1|cut -d " " -f1` y=`ls -l $2|cut -d " " -f1` if [ $x = $y ] then echo "common permission $x" else echo "diffrent permissons" echo "filename is $1 permisson is $x" echo "filename is $2 permisson is $y" fi else echo "$2 not existing" fi else echo "$1 not existing" fi #mit@mit-desktop:~$ gedit lab1b.sh #mit@mit-desktop:~$ sh lab1b.sh 1 abc /* here abc is a file that not present in our system */ #abc not existing #mit@mit-desktop:~$ sh lab1b.sh abc 1 /* here abc is a file that not present in our system */ #abc not existing #mit@mit-desktop:~$ sh lab1b.sh 1 programme2 /* here programme2 is a file that not present in our system */ #programme2 not existing #mit@mit-desktop:~$
  • 3. #"This programme i.e., lab 2 b is written by Ashok" #write a shell script that accepts a path name & creates all the components in that path name as directories. #For ex, if the script is named mpc, then the command mpc a/b/c/d should create directories a, a/b, a/b/c, a/b/c/d echo $1>f1 #echo $1 holds the contents of file f1. x=`cat f1|tr "/" " "` for i in $x #$x holds all the command line arguments. do mkdir $i cd $i done
  • 4. CONCEPT LAB3A ADDING A USER mit@mit-desktop:~$ adduser ashok #if this not work try below command. mit@mit-desktop:~$ sudo adduser ashok #this command is used to add user. Here sudo stands for super user. DISPLAYS PASSWORD FILE OF THE UNIX SYSTEM mit@mit-desktop:~$ cat /etc/passwd #this command is used to password file of the unix system. mit:x:1000:1000:mit,,,,:/home/mit:/bin/bash #mit is user and he as password. ashok:x:1002:1006:Ashok,,,:/home/ashok:/bin/bash #mit is user and he as password. UNDERSTANDING GREP COMMAND mit@mit-desktop:~$ cat > file1 mit ashok mca 1st sem mit@mit-desktop:~$ grep "1st" file1 mit ashok mca 1st sem mit@mit-desktop:~$ cat > file2 mitashokmca1stsem mit@mit-desktop:~$ grep "1st" file2 #grep command is used to search the word "1st" is present or not. mitashokmca1stsem mit@mit-desktop:~$ grep -w "1st" file2 #-w command searches the word iff the contents of the file separated by spaces. mit@mit-desktop:~$ grep -w "1st" file1 mit ashok mca 1st sem mit@mit-desktop:~$ grep -c "1st" file1 1 #-c is used to count the number of occurence of the given word ex: here 1st is occured for 1 time. mit@mit-desktop:~$ grep -n "1st" file1 #-n is used to display in which line the word "1st" is occured 1:mit ashok mca 1st sem
  • 5. #lab3a #write a shell scripts which accepts valid login name as arguments and prints corresponding home directory,if no argument is specified print a sutiable error msg. if [ $# -ne 0 ] then for i in $* do grep -w "$i" /etc/passwd>ash1#ash1 is a file if $i is present in a file /etc/passwd, the line of the contents written in file "ash1" otherwise not. if [ -s ash1 ] #-s checks the file size. then echo "$i is valid user"; #if the file size is not zero then this statement get exexuted. cat ash1 | cut -d ":" -f6 else echo "$i is not a valid user"; #if the file size is zero, this is executed. fi done else echo "no arguments are passed"; fi #mit@mit-desktop:~$ sh ashu.sh mit #mit is valid user #/home/mit #mit@mit-desktop:~$ sh ashu.sh MIT #MIT is not a valid user #mit@mit-desktop:~$ sh ashu.sh Mit #Mit is not a valid user #mit@mit-desktop:~$ sh ashu.sh ashok #ashok is valid user #/home/ashok #mit@mit-desktop:~$ sh ashu.sh vinay #vinay is not a valid user #mit@mit-desktop:~$ sh ashu.sh #command with out any arguments. #no arguments are passed
  • 6. #Write a shell script OR Create a shell script file called File properties that read #file name entered & out put it's permissions. #LAB4A x=1 while [ $x -eq 1 ] do echo "enter u r choice"; read ch echo "u r choice is $ch" case $ch in #$ch contain some value. 1 ) echo "file permission `ls -l $0|cut -d ' ' -f1`";; # -f1 is first fild & $0 is current file itself . 2 )echo "link info `ls -l $0|cut -d ' ' -f2`";; #-f2 is 2nd field 3 )echo "owner info `ls -l $0|cut -d ' ' -f3`";; 4 )echo "group info `ls -l $0|cut -d ' ' -f4`";; 5 )echo "file size `ls -l $0|cut -d ' ' -f5`";; 6 )echo "date of creation `ls -l $0|cut -d ' ' -f6`";; 7 )echo "time `ls -l $0|cut -d ' ' -f7`";; 8 )echo "file name `ls -l $0|cut -d ' ' -f8`";; * )echo "invald option" esac echo "Do you want to contine yes=1 or not=0"; read x done
  • 7. #WAP To Find Smallest Of 3 Numbers. #lab6b read a read b read c small=$a if [ $b -lt $a ] then small=$b fi if [ $c -lt $b ] then small=$c fi echo "$small is smallest number among $a $b & $c" #ashok@ubuntu:~$ sh small.sh #1 #2 #3 #1 is smallest number among 1 2 & 3 #ashok@ubuntu:~$ sh small.sh #99 #2 #55 #2 is smallest number among 99 2 & 55 #ashok@ubuntu:~$ sh small.sh #99 #1058 #-99 #-99 is smallest number among 99 1058 & -99 #ashok@ubuntu:~$
  • 8. CONCEPT LAB7B #WAS Script To Understand Argument Variables $0, $1, $2, $3, $* And $# echo "Programme Name $0" echo "1st Argument $1" echo "2nd Argument $2" echo "3rd Argument $3" echo "All Arguments $*" echo "Total No. Of Arguments $#" #output #ashok@ubuntu:~$ sh 7a.sh 1 2 3 4 #Programme Name 7a.sh #1st Argument 1 #2nd Argument 2 #3rd Argument 3 #All Arguments 1 2 3 4 #Total No. Of Arguments 4 #ashok@ubuntu:~$ #Write A Shell Script to Compute The Sum Of Numbers Passed To It As Arguments On Command Line And Display The Result. #lab7b num=$1 sum=0 a=0 while [ $num -ne 0 ] do rem=`expr $num % 10` num=`expr $num / 10` sum=`expr $sum + $rem` done echo "sum of digits is = $sum" #output #ashok@ubuntu:~$ sh 7b.sh 123 #sum of digits is = 6 #ashok@ubuntu:~$ sh 7b.sh 123456789 #sum of digits is = 45 #ashok@ubuntu:~$ sh 7b.sh 222222 #sum of digits is = 12 #ashok@ubuntu:~$ #Line1 $1 holds 1st Argument. num holds value of $1
  • 9. #write a shell script that accept a list of filenames as its arguments, count and report occurence of each word that is present #in the first argument file on other argument files. #lab9b for pattren in `cat $1` #file is variable like "i" for ex in lab2b programme. do for file in $* #file is variable like "i" for ex in lab2b programme. do if [ $file != $1 ] then x=`grep -iow $pattren $file|wc -l` echo "$file contains the word $pattren $x timesn" fi done done #mcaexam@mit:~$ sh lab9b.sh l1 l2 l3 #l2 contains the word abc 2 times # #l3 contains the word abc 2 times # #l2 contains the word abcd 1 times # #l3 contains the word abcd 1 times # #mcaexam@mit:~$ gedit lab9b.sh #mcaexam@mit:~$ cat l1 #abc #abcd #mcaexam@mit:~$ cat l2 #abc #abc #abcd #mcaexam@mit:~$ cat l3 #abc abc #abcd #mcaexam@mit:~$
  • 10. #Lab5b.sh if [ $# -lt 1 ] then echo "Enter file name as an argument"; else for i in $* do if [ -e $i ] then x=`ls -l $i|cut -d " " -f7` echo "file is $i and creation time is $x"; else echo "$i doesn't exist"; fi done fi #user@user-Inspiron-N5050:~$ sh lab5b.sh f1 #f1 doesn't exist #user@user-Inspiron-N5050:~$ sh lab5b.sh lab5b.sh #file is lab5b.sh and creation time is 18:52 #user@user-Inspiron-N5050:~$
  • 11. #delete a word #lab 8b echo "enter a word" read word for i in $* do grep -iwv "$word" $i > temp cat temp > $i done #user@user-Inspiron-N5050:~$ cat f1 #Ashok #Harish #Prakash #user@user-Inspiron-N5050:~$ cat f2 #inay #Ashok #Mahendra #user@user-Inspiron-N5050:~$ sh lab8b.sh f1 f2 #enter a word #Ashok #user@user-Inspiron-N5050:~$ cat f1 #Harish #Prakash #user@user-Inspiron-N5050:~$ cat f2 #inay #Mahendra #user@user-Inspiron-N5050:~$
  • 12. #labb11b.sh if [ $3 -ge $2 ] then n=`cat $1|wc -l` if [ $n -ge $3 ] then x=`expr $3 - 1` y=`expr $x - $2` head -$x $1|tail -$y else echo "insufficient number of lines"; fi else echo "ending line number should be greater than starting line number "; fi #user@user-Inspiron-N5050:~$ cat f1 #hari #ashok #prasad #prakash #mary #koppal #udupi #ubuntu #unix #windows #user@user-Inspiron-N5050:~$ sh labb11b.sh f1 2 6 #prasad #prakash #mary #user@user-Inspiron-N5050:~$
  • 13. #lab11a.sh k=$2 if [ $k -lt 0 ] then k=`expr $k * -1` fi i=$1 j=1 pow=1 while [ $j -le $k ] do pow=`expr $pow * $i` j=`expr $j + 1` done if [ $2 -lt 0 ] then echo "scale=3;`expr 1/$pow`"|bc else echo "$1 to the power of $2 is $pow" fi #user@user-Inspiron-N5050:~$ sh lab11a.sh 2 3 #2 to the power of 3 is 8 #user@user-Inspiron-N5050:~$ sh lab11a.sh 2 -3 #.125 #user@user-Inspiron-N5050:~$