Linux
Linux
The kernel is the core part of an operating system (OS) It acts as an interface
between the software (applications) and hardware (CPU, memory, etc.). It manages
system resources, such as memory, processes, device drivers, and file systems, and
ensures that programs can run effectively without directly accessing hardware. When
user logins into system, kernel checks whether he/she is an authorized user or not.
there will be only one kernel for an O.S
Shell is known as a command-line Interpreter. It acts as an interface between user
& Kernal(e.g., Bash, Zsh).
Utility refers to a small, specialized program designed to perform a specific task
or set of tasks. Utilities are typically command-line tools that help users manage
and manipulate files, processes, system resources, and perform other system
administration functions.
Features of Linux:
Open Source
Multi Tasking Capability
Multitasking with Multi-user Capabilities
Security
Portability
Stability and Reliability
Customizability
Command Line Interface
Graphical User Interface (GUI)
Inserting Commands:
There are many ways to be in insert mode
i Command Type (Press i)
a Inserts text after current Cursor Location.
A Inserts text at the end of current Cursor Location.
Deleting Characters:
X(Upper Case) Deletes Character before Cursor Location.
x(Lower Case) Deletes Character at Cursor Location
fgrep:
fixed global regular expression.
It is the fast version of grep.It searches only strings, won’t support regular
expressions.
Syntax:
fgrep option string filename
fgrep contains all options which are supported by grep(-n,-I,-l,-v,-w)and –x
-x :outputs only lines that are exactly equal to given string
egrep:
Extended Global Regular Expression.
Syntax:
egrep option regularexpression filename
Egrep supports all regular expressions supported by grep and it supports other
regular expressions like *,?,+,|
*:matches previous atom zero or more times.
+:matches previous atom one or more times.
?:matches previous atom zero or one time.
|:Alternation.
Sed Address Format 2: M~N with “p” command prints every Nth line starting from line
M.
Syntax: sed -n ‘M~N’p filename
Ex: To prints every 2nd line starting from 3rd line .
$ sed -n '3~2‘p unixcommand
Output : Implicit
Operating system
3. Sed Address Format 3: M,N with “p” command prints Mth line to Nth line.
Syntax: sed -n ‘M,N’p filename
Ex :To prints from 2nd line to 4th line from input file
$sed -n ‘2,4'p unixcommand
Output: Unix programming
Implicit
Explicit
Like any other programming language Awk also has lot of operators for number and
string operations. In this article let us discuss about all the key awk operators.
There are two types of operators in Awk.
Unary Operator – Operator which accepts single operand is called unary operator.
Binary Operator – Operator which accepts more than one operand is called binary
operator.
let us review about awk loop statements – while, do while, for loops, break,
continue, and exit statements .
Awk looping statements are used for performing set of actions again and again in
succession.
It repeatedly executes a statement as long as condition is true.
Awk has number of looping statement as like ‘C’ programming language.
Awk While Loop
Syntax: while(condition)
actions
while is a keyword. condition is conditional expression actions are body of the
while loop which can have one or more statement. If actions has more than one
statement, it has to be enclosed with in the curly braces.
ex:-
BEGIN{}
{
i=1;
while (i <= 3)
{
print $i;
i++;
}
}
END{}
Read-only Variables:
The shell provides a way to mark variables as read-only by using the read only
command. After a variable is marked read-only, its value cannot be changed.
For example, following script would give error while trying to change the value of
NAME:
Example :
NAME="Zara Ali“
readonly NAME
NAME="Qadiri"
echo $NAME
This would produce following result:
/bin/sh: NAME: This variable is read only.
3.$PS2 - The "PS2" environment variable defines the secondary prompt, This is the
prompt you see when you execute a multi-line command, such as "for" or "if." You
also see it when you forget to terminate a quote. The default value is "> ."
To display prompt setting :: $ echo $PS2
>
4. $ SHENV :It the variable is not set ,the shell searches the user’s home
directory for “.profile “ startup when a new shell is created.
if the variable is set, then the shell searches the directory specified by
SHENV
To display environment :: $ set (OR) $ printenv (OR) $ env
Write shell scripts for the Menu driven program which has the following options.
i)display date
ii) list of users who have currently logged in.
iii) present working directory. iv) exit.
Program:
ch='y'
while [ $ch = 'y' ]
do echo "enter the choice"
echo "1 date"
echo "2 who"
echo "3 ls"
echo "4 pwd"
echo "5 exit"
read choice
case $choice in
1) date ;;
2) who ;;
3) ls ;;
4) pwd ;;
5) exit ;;
*) break
esac
echo "do u wish to continue (y/n)"
read choice
done