INTRODUCTION OF LINUX
Linux is an operating system. It is an open source operating system. An operating system is the
software that directly manages a system’s hardware and resources, like CPU memory between all
of your software and physical resources that do the work and storage. The operating system sites
between applications and make the connection.
History of Linux
The UNIX operating system was conceived and implemented in 1960’s and first released in
1970. Its wide availability and portability meant that it was widely adopted, copied and modified
by institutions and business organizations. In 1985, Richard Stallman created the free software
foundation and developed the GNU general public license.
Linux is a freely distributable version of UNI Linus torvald, who was then a student at
university of, Helsinki in finland developed linux in 1991. The linux kernel was first released to
the public on 17 september, 1991 for X86 PC architecture. Linux is unique operating system.
Advantages of Linux
Let us now discuss some advantages of Linux in brief:
1.Open Source
One of the main advantages of Linux is that it is an open source operating system i.e. its source
code is easily available for everyone. Anyone capable of coding can contribute, modify, enhance
and distribute the code to anyone and for any purpose.
2. Security
Linux is more secure in comparison to other operating systems such as Windows. Linux is not
completely secure as there is some malware for it also but it is less vulnerable than others. Every
program in Linux whether an application or a virus needs authorization from the administrator in
the form of a password. Unless the password is typed virus won’t execute. There is no
requirement of any anti-virus program in Linux.
3. Revive older computer systems
Linux helps you to use or utilize your old and outdated computer systems as a firewall, router,
backup server or file server and many more. There are many distributions available to use
according to your system capability. As you can use Puppy Linux for low- end systems.
Linux system requirement
You can run data replication on the following version of 64- bit Linux operating system:
Red Hat enterprise Linux 6.5
Red Hat enterprise Linux 6.6
Red Hat enterprise Linux 6.7
Red Hat enterprise Linux 6.8
Red Hat enterprise Linux 6.9
Red Hat enterprise Linux 7
Red Hat enterprise Linux 7.1
Red Hat enterprise Linux 7.2
Red Hat enterprise Linux 7.3
Red Hat enterprise Linux 7.4
SUSE Linux enterprise server 11 SP4
SUSE Linux enterprise server 12 SP3
The following table shows the recommended processor type, memory and disk space.
System characteristics Recommended
Processor 64-bit opteron EM 64T
RAM 1GB or greater
Swap space 1GB or greater
Disk space 500 MB free spca
Cal command in Linux
If a user wants a quick view of the calendar in the Linux terminal, cal is the command for you.
By default, the cal command shows the current month calendar as output.
cal :
command is a calendar command in Linux which is used to see the calendar of a specific
month or a whole year.
Syntax:
cal [ [ month ] year]
The rectangular bracket means it is optional, so if used without an option, it will display a
calendar of the current month and year.
cal :
Shows current month calendar on the terminal with the current date highlighted.
cal -y :
Shows the calendar of the complete current year with the current date highlighted.
Cal2018:
Shows the whole calendar of the year.
cal 2018 | more :
But year may not be visible in the same screen use more with cal use spacebar to scroll
down.
cal -3 :
Shows calendar of previous, current and next month
cal -j :
Shows the calendar of the current month in the Julian calendar format not in the
default Gregorian calendar format. In Julian calendar format, the date does not reset to 1 after
every month’s end i.e. after 31st Jan, Feb will start as 32nd Feb, not as 1st Feb. But in the
Gregorian calendar format, the date is reset to 1 after every month’s end i.e. after 31st Jan, Feb
will start as of 1st Feb.
Who command in Linux
Who command is used to find out the following information:
1. Time of last system boot
2. Current run level of the system
3. List of logged in users and more.
Description :
The who command is used to get information about currently logged in user on to
system.
Syntax :
$who [options] [filename]
Examples :
1. The who command displays the following information for each user currently
logged in to the system if no option is provided.
2. Login name of the users
3. Terminal line numbers
4. Login time of the users in to system
5. Remote host name of the user
Ls Command
The ls is the list command in Linux. It will show the full list or content of your directory. Just
type ls and press the enter key. The whole content will be shown.
Example:
1. ls
Below, you can see, after entering ls command, we got the whole content list of /home/sssit
directory.
Linux in command option
ls -li This command prints the index number if file is in the first column.
ls -p It is used to identify the directory easily by marking the directories with a slash (/)
line sign.
ls -r It is used to print the list in reverse order.
ls -R It will display the content of the sub-directories also.
Date Command
Date command is used to display the system date and time. Date command is also used to set
date and time of the system. By default the date command displays the date in the time zone on
which Unix/Linux operating system is configured. You must be the super-user (root) to change
the date and time.
Syntax:
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
List of Format specifiers used with date command:
%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.
Syntax: $date +% [format-option]
Ps command in Linux
As we all know Linux is a multitasking and multi-user system. So, it allows multiple processes to
operate simultaneously without interfering with each other. Process is one of the important
fundamental concepts of the Linux OS. A process is an executing instance of a program and
carries out different tasks within the operating system.
Linux provides us utility called ps for viewing information related with the processes on a
system which stands as abbreviation for “Process Status”. ps command is used to list the
currently running processes and their PIDs along with some other information depends on
different options. It reads the process information from the virtual files in /proc file-system.
/proc contains virtual files, this is the reason it’s referred as a virtual file system.
ps provides numerous options for manipulating the output according to our need.
Syntax –
ps [options]
1.Options for ps Command :
2.Simple process selection :
Shows the processes for the current shell –
[root@rhel7 ~]# ps
PID TTY TIME CMD
12330 pts/0 00:00:00 bash
21621 pts/0 00:00:00 ps
1.Result contains four columns of information.
PID – the unique process ID
TTY– terminal type that the user is logged into
TIME – amount of CPU in minutes and seconds that the process has been running
CMD – name of the command that launched the process.
Cat command
Cat (concatenate) command is very frequently used in Linux. It reads data from the file and gives
their content as output. It helps us to create, view, and concatenate files. So let us see some
frequently used cat commands.
Wc command in Linux
wc stands for word count. As the name implies, it is mainly used for counting purpose.
It is used to find out number of lines, word count, byte and characters
count in the files specified in the file arguments. By default it displays four-columnar output.
First column shows number of lines present in a file specified, second column shows number of
words present in the file, third column shows number of characters present in file and fourth
column itself is the file name which are given as argument.
Syntax: wc [OPTION]... [FILE]...
Echo Command
Echo command in linux is used to display line of text/string that are passed as an argument . This
is a built in command that is mostly used in shell scripts and batch files to output status text to
the screen or a file.
Syntax : echo [option] [string]
Displaying a text/string :
Syntax : echo [string]
Man Command
Man command in Linux is used to display the user manual of any command that we can run on
the terminal. It provides a detailed view of the command which includes NAME, SYNOPSIS,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES,
VERSIONS, EXAMPLES, AUTHORS and SEE ALSO.
Every manual is divided into the following sections:
Executable programs or shell commands
System calls (functions provided by the kernel)
Library calls (functions within program libraries
Games
Special files (usually found in /dev)
File formats and conventions eg /etc/passwd
Miscellaneous (including macro packages and conventions), e.g. groff(7)
System administration commands (usually only for root)
Kernel routines [Non standard]
Syntax :
$man [OPTION]... [COMMAND NAME]...
Options and Examples
1. No Option: It displays the whole manual of the command.
Syntax :
$ man [COMMAND NAME]
Uname Command
The command ‘uname‘ displays the information about the system.
Syntax:
uname [OPTION]
tty command in Linux
Linux operating system represents everything in a file system, the hardware devices that we
attach are also represented as a file. The terminal is also represented as a file. There a command
exists called tty which displays information related to terminal. The tty command of terminal
basically prints the file name of the terminal connected to standard input. tty is short of teletype,
but popularly known as a terminal it allows you to interact with the system by passing on the
data (you input) to the system, and displaying the output produced by the system.
Syntax: tty [OPTION]....
stty command in Linux
stty command in Linux is used to change and print terminal line settings. Basically, this
command shows or changes terminal characteristics.
Syntax:
stty [-F DEVICE | --file=DEVICE] [SETTING]...
stty [-F DEVICE | --file=DEVICE] [-a|--all]
stty [-F DEVICE | --file=DEVICE] [-g|--save]
Example: It will display the characteristics of the terminal.
Write the Commands to make, open and remove the directories.
Commands:-
Mkdir (file name.sh) :- for create a directory
Bash (file name.sh) :- for open the directory
Rmdir (file name.sh) :- for remove the directory
OUTPUT
1.WAP to find the year is leap year or not leap year.
echo "enter the year"
read yr
if [ `expr $yr % 4` -eq 0 ]
then
echo "year is leap"
else
echo "year is not leap"
fi
OUTPUT
2.WAP to find the greater number.
a=20;b=50;
if [$b -gt $a]
then
echo "b is greater"
else
echo "a is greater"
fi
OUTPUT
3.WAP to find the Reverse of numbers.
echo "enter the number"
read num
sum=0;
while [ $num -gt 0 ]
do
mod=$((num % 10))
sum=$((sum * 10 + mod))
num=$((num / 10))
done
echo $sum
Output
4.WAP to find the sum of digits.
echo "enter the number"
read num
sum=0;
while [ $num -gt 0 ]
do
mod=$((num % 10))
sum=$((sum + mod))
num=$((num / 10))
done
Output
5.WAP to find the factorial of a number.
test.sh
echo " enter a number"
read num
a=1;
while [ $num -gt 1 ]
do
a=$((a * num)) #a = a * num
num=$((num - 1)) #num = num - 1
done
echo $a
Output
6. WAP to implement the while loop condition.
i=1
while [ $i -le 20 ]
do
echo $i
i=$(($i+1))
done
Output
7.WAP to implement the while break and continue statement.
i=1
while :
do
echo $i
if [ $i -eq 20 ];
then
echo "This is end of the loop"
break
if
((i++))
done
Output
8.WAP to implement the while loop with Continue statement.
i=1
while [ $i -lt 30 ];
do
((i++))
if [[ $(( $i % 5 )) -ne 0 ]];
then
continue
if
echo $i
done
Output
9.WAP to implement the Arithmetic operator.
read - p 'Enter a : 'a
read
- p 'Enter b : 'b
add
= $((a + b))
echo Addition of a and b are $add
sub
= $((a - b))
echo Subtraction of a and b are $sub
mul
= $((a * b))
echo Multiplication of a and b are $mul
div
= $((a / b))
echo division of a and b are $div
mod
= $((a % b))
echo Modulus of a
and b are $mod
((++a))
echo Increment
operator when applied on "a" results into a = $a
((--b))
echo Decrement
operator when applied on "b"results into b = $b
Output
10.WAP to implement Relational operators.
read -p 'Enter a : 'a
read -p 'Enter b : 'b
if(( $a==$b ))
then
echo a is equal to b.
else
echo a is not equal to b.
fi
if(( $a!=$b ))
then
echo a is not equal to b. OUTPUT
else
echo a is equal to b.
fi
if(( $a<$b ))
then
echo a is less than b.
else
echo a is not less than b.
fi
if(( $a<=$b ))
then
echo a is less than or equal to b.
else
echo a is not less than or equal to b.
fi
if(( $a>$b ))
then
echo a is greater than b.
else
echo a is not greater than b.
fi
if(( $a>=$b ))
then
echo a is greater than or equal to b.
else
echo a is not greater than or equal to b.
fi
11.WAP to implement the Logical operator.
read -p 'Enter a : 'a
read -p 'Enter b : 'b
if(($a == "true"& $b == "true"))
then
echo Both are true. OUTPUT
else
echo Both are not true.
fi
if(($a == "true"|| $b == "true"))
then
echo Atleast one of them is true.
else
echo None of them is true.
fi
if(( ! $a == "true" ))
then
echo "a"was initially false.
else
echo "a"was initially true.
Fi
12.WAP to implement the Bitwise operator. OUTPUT
read -p 'Enter a : 'a
read -p 'Enter b : 'b
bitwiseAND=$(( a&b ))
echo Bitwise AND of a and b is $bitwiseAND
bitwiseOR=$(( a|b ))
echo Bitwise OR of a and b is $bitwiseOR
bitwiseXOR=$(( a^b ))
echo Bitwise XOR of a and b is $bitwiseXOR
bitiwiseComplement=$(( ~a ))
echo Bitwise Compliment of a is $bitiwiseComplement
leftshift=$(( a<<1 ))
echo Left Shift of a is $leftshift
rightshift=$(( b>>1 ))
echo Right Shift of b is $rightshift
13.Create structures using arrays.
@echo off
set struct[0].name=John
set struct[0].age=12
set struct[0].gender="M"
set struct[1].name=Kevin
set struct[1].age=20
set struct[1].gender="M"
set struct[2].name=Jessie
set struct[2].age=15
set struct[2].gender="F"
FOR /L %%i IN (0 1 2) DO (
call echo Name: %%struct[%%i].name%%, Age:^
%%struct[%%i].age%%, Gender:, %%struct[%%i].^
gender%%
)
Output
14.WAP to create a numbered menu to allow a user (or B.Tech student) to select the
department.
select department in CS IT ECE EE
do
case $department in
CS)
echo "I am from CS department."
;;
IT)
echo "I am from IT department."
;;
ECE)
echo "I am from ECE department."
;;
EE)
echo "I am from EE department."
;;
none)
break
;;
*) echo "Invalid selection"
;;
esac
done
OUTPUT
INDEX
Sr no. Content Page No. Remarks
1 Introduction of Linux
2 History of Linux
3 Advantages of Linux
4 Cal command
5 Who command
6 Ls command
7 Date command
8 Ps command
9 Cat command
10 Wc command
11 Echo command
12 Man command
13 Uname command
14 Tty command
15 Stty command
16 Making, open and remove the directories
Linux Commands
1 WAP Find the year is leap year or not leap year
2 WAP find the greater number.
3 WAP find the reverse number.
4 WAP to find the sum of digits.
5 WAP to find the factorial of a number
6 WAP to implement the while loop conditions
WAP to implement the while Break and continue
7
statement
8 WAP to while loop with Continue statement
9 WAP to implement Arithmetic operator.
10 WAP to implement Relational operators.
11 WAP to implement Logical operators
12 WAP to implement Bitwise operators
13 WAP to Create Structures using Arrays.
14 WAP to create a numbered menu to allow a user (or
B.Tech student) to select the department.