SlideShare a Scribd company logo
Dr. D. P.
Mishra
Digitally signed by Dr. D. P. Mishra
DN: cn=Dr. D. P. Mishra, o=durg,
ou=BIT, email=dpmishra@bitdurg.
ac.in, c=IN
Date: 2023.02.14 13:34:20 +05'30'
grep command
• grep stands for global search for regular expression and print.
• The grep filter searches a file for a particular pattern of characters, and
displays all lines that contain that pattern
• searched pattern in the file is referred as the regular expression
• Syntax :
• grep [options] pattern [files]
• Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Example
$cat > geekfile.txt
unix is great os. unix was developed in Bell labs.
learn operating system.
Unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
$grep -i "UNix" geekfile.txt
Output:
unix is great os. unix was developed in Bell labs.
Unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
egrep
• The egrep (Extended Global Regular Expression Print) command
• It is text processing tool that searches for patterns or regular
expressions in a specified location.
• The tool provides the same output as grep in faster mode
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
fgrep
• The fgrep command displays the file that contains the matched line if
you specify more than one file in the File parameter.
• The fgrep command differs from the grep and egrep commands
because it searches for a string instead of searching for a pattern
• fgrep is equivalent to grep -F command and it uses a fixed string for
search and hence it performs a faster search
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ fgrep [OPTIONS] PATTERNS [FILES] $ cat input.txt
cut command
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
• Linux cut command is useful for selecting a specific column of a file.
• It is used to cut a specific sections by byte position, character, and field
and writes them to standard output.
• It cuts a line and extracts the text data
• Syntax :
• $ cut OPTION... [FILE]...
Example
• $ cat > state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Apply following commands on state.txt:
List Without ranges: $ cut -b 1,2,3 state.txt
List with ranges : $ cut -b 1-3,5-7 state.txt
$ cut -b 1- state.txt
$ cut -b -3 state.txt
$ cut -c 2,5,7 state.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Paste Command
• Paste command is used to join files horizontally (parallel merging) by
outputting lines consisting of lines from each file specified, separated
by tab as delimiter, to the standard output.
• When no file is specified, or put dash (“-“) instead of file name, paste
reads from standard input and gives output as it is until a interrupt
command [Ctrl-c] is given.
• Syntax: paste [OPTION]... [FILES]...
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ cat > capital
Itanagar
Dispur
Hyderabad
Patna
Raipur
$ paste number state capital
$ paste -d "|" number state capital
1|Arunachal Pradesh|Itanagar
2|Assam|Dispur
3|Andhra Pradesh|Hyderabad
4|Bihar|Patna
5|Chhattisgrah|Raipur
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Example
unmae & wget command
$ uname
• You can use the command to get the release number, version of Linux, and
much more.
• The “-a” flag is used to get detailed information.
$ wget
• You can use the wget command to download the content from the internet;
• for instance, the following command will download VirtualBox.
$ wget https://download.virtualbox.org/virtualbox/6.1.26/VirtualBox-6.1.26-
145957-Win.exe
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
apt-get or –apt command
• Most important and most used commands of Ubuntu that works with
Ubuntu Advanced Packaging Tool (APT);
• You can use this “-apt-get” or “-apt” to install or remove packages
• The “apt” requires sudo privileges to successfully execute the
command.
• Syntax : $ sudo apt install [packagename]
• To install vlc media player package use
• $ sudo apt install vlc
• To remove package - $ sudo apt remove [packagename]
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
history command
• The history command shows the
list of commands (with numeric
numbers) executed
• $ history
• One can execute any of the listed
commands
• If you want to execute the 2nd
command (which is apt update
command), then you have to write
“!74” to get the result of that
command:
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
ps command
• ps - using the -ps command, you will be able to get the list of
processes.
$ ps
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
w command
• W command will display the user details that are currently logged into
the system
• $ w
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
passwd
• passwd - With the help of the passwd command, you can change the
password of your Ubuntu user:
• You must pass “username” to “passwd” to change the password of
that; for example, the command given below will change the password
of user “6cse01”
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
hostname command
• This command will print your hostname on the terminal
• $ hostname
• bitlinux@6cse01 $ bitlinux
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
ping command
• Ping - you can use the ping command to check the connectivity to your server;
• for example, the command below will ping to YouTube and also prints the
response time
• $ping hostname or ip-address
• $ ping youtube.com
• $ ping google.com
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ uptime -shows how long system is running
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ users – shows username who are currently logged in
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ service – call and execute script
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ service --status-all
$ ps – display about running process
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
kill, killall and pkill
• kill terminates processes based on Process ID number (PID),
• While the killall and pkill commands terminate running processes
based on their names and other attributes.
• Example
$ ps
PID TTY TIME CMD
11571 pts/20 00:00:00 bash
22166 pts/20 00:00:00 ps
$ kill -s 0 11571
$ kill -s 0 11579
bash: kill: (11579) - No such process
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ pmap – memory map of process
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ free – shows memory status
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ netstat – display network status
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ nslookup – check domain name of ip info
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ route - list routing table for your server
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
ftp command
• Here, ftp stands for File Transfer Protocol. This utility helps you upload
and download your file from one computer to another computer.
• $ftp hostname or ip-address
• $ftp 172.16.0.100
• ftp> dir
• ftp> get <filename>
• ftp> quit
• 221 Goodbye.
• $
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
More Commands
• join
• Tee
• Comm
• Cmp
• Diff
• tr
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Text Editing with Vi Editor
(vi- Visual Editor)
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Vi Editor
• The VI editor is a screen based editor used by many unix users.
• It is the default editor that comes with the UNIX operating systems
and is called vi (visual editor).
• The improved version of vi is called the vim editor ( vi improved) is
available with Linux systems.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Modes of vi editor
• There are three basic modes of vi:-
1. Command mode
2. Insert mode
3. Line mode
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
1. Command mode:-
• This the default when you enter vi.
• In command mode - most letters, or short sequence of letters, that
you type will be interpreted as commands, without explicitly pressing
Enter.
• If you press ESC when you’re in command mode, your terminal will
beep at you.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
2. Insert Mode
• Insert mode:- In insert mode, whatever you type is inserted in the file
at the cursor position.
• Type i to enter insert mode from command mode;
• press ESC to end insert mode, and return to command mode.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
3. Line mode
• Line mode:- Use line mode to enter line oriented commands.
• To enter line mode from command mode, type a colon(:).
• Your cursor moves to the bottom of the screen, by a colon prompt.
• Type a line mode command and then press ENTER.
• Each time you use a line mode command, you must
• type a colon to enter line mode,
• then type the command by the colon prompt at the bottom of the screen,
• then press ENTER when you finish typing the command
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Starting and stopping vi
• To edit file
$ vi generalnote
• Above command starts vi and allocates a memory buffer for
file generalnote
• If the file already exists, text in the file will be displayed on the screen.
• You can't add any text to the file until you go into insert mode because
vi started in the command mode.
• The tilde character (~) you see in the screen shot shows that the file
has no text in these lines.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Starting and stopping vi
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
• The tilde character (~) you see in the screen
shot shows that the file has no text in these
lines.
• To switch to insert mode, press the
i character
• Press the Esc & : key to return to command
mode.
• To save file use :w command.
• To quit the editor use :q command
• Use : x or wq to save and quit in one step
Cursor Movement Commands
• The mouse does not move the cursor
within the vi editor screen. You must
have the key commands listed.
• Before using any of these
commands, make sure that you are
in the command mode by pressing
the ESC & : key.
• You can also instruct the vi editor to
display the line number with each
line using the :set
number command.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Symbol Function
l Move one character right
h Move one character left
j Move one line down
k Move one line up
< space > Move one character right
G Go to last line of the file
nG Go to line number n in the file
$ Go to end of current line
^ Go to start of line
w Go to beginning of next word
b Go to beginning of previous word
e Move to end of word
H Go to first line of screen
M Go to middle line of screen
L Go to last line of screen
( Go to beginning of sentence
) Go to end of sentence
{ Go to beginning of paragraph
} Go to end of paragraph
Inserting text in vi
Command Effect
i Start inserting text at the current cursor location.
I Start inserting text at the beginning of the current line.
a Start inserting text at the next character position relative to the current cursor
location.
A Start inserting text at the end of the current line.
o Append a blank line just below the current line and start inserting text from the
beginning of that line.
O Append a blank line just above the current line and start inserting text from the
beginning of that line.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Deleting text in vi
Command Effect
x Delete character at current cursor location.
nx Delete n characters starting at current cursor location.
X Delete previous character from the current cursor location.
nX Delete n previous characters from the current cursor location.
dd Delete current line.
db Delete previous word.
dw Delete from current cursor location to the end of word.
dG Delete to the end of file including current line.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Text replacement command in vi
Command Effect
r Replace current character remaining in command mode
s Replace current character and go to insert mode
R Replace multiple characters until the key is pressed
cw Change to the beginning of next word
cc Change entire line
cG Change to the end of file
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Cut, Copy, and Paste Commands
Command Effect
yy Copy or yank current line
nyy Copy n lines starting from current line position
p Paste yanked text after the current cursor position
P Paste yanked text before the current cursor position
:m a Move current line and paste after line number a
:a,bmc Move lines from a to b and paste after line number c
:a,btc Copy lines from a to b and paste after line number c
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Shell Scripting /Programming
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
What is in a shell script?
• A shell script is a text file that contains a sequence of commands for a
UNIX-based operating system.
• Shell scripting is an important part of process automation in Linux.
• Scripting helps you write a sequence of commands in a file and then
execute them.
• This saves you time because you don't have to write certain
commands again and again
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
How to write shell script
• Following steps are required to write shell script:
• (1) Use any editor like vi or gedit to write shell script.
• (2) After writing shell script set execute permission
• (3) Execute shell script as
• syntax:
• bash shell-script-name
• sh shell-script-name
• ./your-script-name
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
First shell script
echo "Our first script"
echo "--------------------------------------------"
echo # This inserts an empty line in output.
echo "We are currently in the following directory"
pwd
echo "This directory contains the following files"
ls
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Prog1: Write following shell script, save it, execute it and
note down the it's output.
$ vi ginfo
#
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
echo "Today is c ";date
echo "Number of user login : c" ; who | wc -l
echo "Calendar"
cal
exit 0
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Prog 2 : Using if-else to check whether two numbers are equal
a=10
b=20
if [ $a -eq $b ]
then
echo " Number is equal "
else
echo " number not equal "
fi
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
C- Program in Linux Environment
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
First C Program
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Steps:
• Write program in vi editor
• Save with .c extension
• Comiple :
$ gcc progname.c
• Run ;
$ ./a.out
Filters & Vi Editor

More Related Content

Similar to Filters & Vi Editor

Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Line
azzamhadeel89
 
Group13
Group13Group13
Ultimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationUltimate Unix Meetup Presentation
Ultimate Unix Meetup Presentation
JacobMenke1
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Line
azzamhadeel89
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
Vinoth Sn
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filtersAcácio Oliveira
 
Linux
LinuxLinux
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines
Arif Wahyudi
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
MuhammadShoaibHussai2
 
How to admin
How to adminHow to admin
How to admin
yalegko
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
Kedar Bhandari
 
linux OS.pptx
linux OS.pptxlinux OS.pptx
linux OS.pptx
Shinwa Hasan
 
50 most frequently used unix linux commands (with examples)
50 most frequently used unix   linux commands (with examples)50 most frequently used unix   linux commands (with examples)
50 most frequently used unix linux commands (with examples)
Rodrigo Maia
 
linux cmds.pptx
linux cmds.pptxlinux cmds.pptx
linux cmds.pptx
divyanshianand3
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
Tanzeem Syed
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
KarthickS942388
 

Similar to Filters & Vi Editor (20)

Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Line
 
Linux
LinuxLinux
Linux
 
Group13
Group13Group13
Group13
 
Ultimate Unix Meetup Presentation
Ultimate Unix Meetup PresentationUltimate Unix Meetup Presentation
Ultimate Unix Meetup Presentation
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Line
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 
How to admin
How to adminHow to admin
How to admin
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
linux OS.pptx
linux OS.pptxlinux OS.pptx
linux OS.pptx
 
50 most frequently used unix linux commands (with examples)
50 most frequently used unix   linux commands (with examples)50 most frequently used unix   linux commands (with examples)
50 most frequently used unix linux commands (with examples)
 
linux cmds.pptx
linux cmds.pptxlinux cmds.pptx
linux cmds.pptx
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
 
Nithi
NithiNithi
Nithi
 

More from BIT DURG

HTML_DOM
HTML_DOMHTML_DOM
HTML_DOM
BIT DURG
 
JavaScript
JavaScriptJavaScript
JavaScript
BIT DURG
 
Understanding WWW
Understanding WWWUnderstanding WWW
Understanding WWW
BIT DURG
 
Computer Networks
Computer NetworksComputer Networks
Computer Networks
BIT DURG
 
Computer Basics
Computer Basics Computer Basics
Computer Basics
BIT DURG
 
ISDN & ATM
ISDN & ATMISDN & ATM
ISDN & ATM
BIT DURG
 
Transport Control Protocol
Transport Control ProtocolTransport Control Protocol
Transport Control Protocol
BIT DURG
 
Routing Protocols
Routing ProtocolsRouting Protocols
Routing Protocols
BIT DURG
 
Internet Protocol.pdf
Internet Protocol.pdfInternet Protocol.pdf
Internet Protocol.pdf
BIT DURG
 
Intternetworking With TCP/IP
Intternetworking With TCP/IPIntternetworking With TCP/IP
Intternetworking With TCP/IP
BIT DURG
 
Computer Network Basics
Computer Network BasicsComputer Network Basics
Computer Network Basics
BIT DURG
 
MySQL
MySQL MySQL
MySQL
BIT DURG
 
Types of Linux Shells
Types of Linux Shells Types of Linux Shells
Types of Linux Shells
BIT DURG
 
File Access Permission
File Access PermissionFile Access Permission
File Access Permission
BIT DURG
 
Control flow and related shell cripts
Control flow and related shell criptsControl flow and related shell cripts
Control flow and related shell cripts
BIT DURG
 
Basic Shell Programs
Basic Shell ProgramsBasic Shell Programs
Basic Shell Programs
BIT DURG
 
Linux Installation
Linux InstallationLinux Installation
Linux Installation
BIT DURG
 
Basics of GNU & Linux
Basics of GNU & LinuxBasics of GNU & Linux
Basics of GNU & Linux
BIT DURG
 
National youth day
National youth dayNational youth day
National youth day
BIT DURG
 
Visual Basic Tutorials
Visual Basic TutorialsVisual Basic Tutorials
Visual Basic Tutorials
BIT DURG
 

More from BIT DURG (20)

HTML_DOM
HTML_DOMHTML_DOM
HTML_DOM
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Understanding WWW
Understanding WWWUnderstanding WWW
Understanding WWW
 
Computer Networks
Computer NetworksComputer Networks
Computer Networks
 
Computer Basics
Computer Basics Computer Basics
Computer Basics
 
ISDN & ATM
ISDN & ATMISDN & ATM
ISDN & ATM
 
Transport Control Protocol
Transport Control ProtocolTransport Control Protocol
Transport Control Protocol
 
Routing Protocols
Routing ProtocolsRouting Protocols
Routing Protocols
 
Internet Protocol.pdf
Internet Protocol.pdfInternet Protocol.pdf
Internet Protocol.pdf
 
Intternetworking With TCP/IP
Intternetworking With TCP/IPIntternetworking With TCP/IP
Intternetworking With TCP/IP
 
Computer Network Basics
Computer Network BasicsComputer Network Basics
Computer Network Basics
 
MySQL
MySQL MySQL
MySQL
 
Types of Linux Shells
Types of Linux Shells Types of Linux Shells
Types of Linux Shells
 
File Access Permission
File Access PermissionFile Access Permission
File Access Permission
 
Control flow and related shell cripts
Control flow and related shell criptsControl flow and related shell cripts
Control flow and related shell cripts
 
Basic Shell Programs
Basic Shell ProgramsBasic Shell Programs
Basic Shell Programs
 
Linux Installation
Linux InstallationLinux Installation
Linux Installation
 
Basics of GNU & Linux
Basics of GNU & LinuxBasics of GNU & Linux
Basics of GNU & Linux
 
National youth day
National youth dayNational youth day
National youth day
 
Visual Basic Tutorials
Visual Basic TutorialsVisual Basic Tutorials
Visual Basic Tutorials
 

Recently uploaded

Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 

Recently uploaded (20)

Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 

Filters & Vi Editor

  • 1. Dr. D. P. Mishra Digitally signed by Dr. D. P. Mishra DN: cn=Dr. D. P. Mishra, o=durg, ou=BIT, email=dpmishra@bitdurg. ac.in, c=IN Date: 2023.02.14 13:34:20 +05'30'
  • 2. grep command • grep stands for global search for regular expression and print. • The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern • searched pattern in the file is referred as the regular expression • Syntax : • grep [options] pattern [files] • Options Description -c : This prints only a count of the lines that match a pattern -h : Display the matched lines, but do not display the filenames. -i : Ignores, case for matching -l : Displays list of a filenames only. -n : Display the matched lines and their line numbers. -v : This prints out all the lines that do not matches the pattern -e exp : Specifies expression with this option. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 3. Example $cat > geekfile.txt unix is great os. unix was developed in Bell labs. learn operating system. Unix linux which one you choose. uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. $grep -i "UNix" geekfile.txt Output: unix is great os. unix was developed in Bell labs. Unix linux which one you choose. uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 4. egrep • The egrep (Extended Global Regular Expression Print) command • It is text processing tool that searches for patterns or regular expressions in a specified location. • The tool provides the same output as grep in faster mode Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 5. fgrep • The fgrep command displays the file that contains the matched line if you specify more than one file in the File parameter. • The fgrep command differs from the grep and egrep commands because it searches for a string instead of searching for a pattern • fgrep is equivalent to grep -F command and it uses a fixed string for search and hence it performs a faster search Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg $ fgrep [OPTIONS] PATTERNS [FILES] $ cat input.txt
  • 6. cut command Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg • Linux cut command is useful for selecting a specific column of a file. • It is used to cut a specific sections by byte position, character, and field and writes them to standard output. • It cuts a line and extracts the text data • Syntax : • $ cut OPTION... [FILE]...
  • 7. Example • $ cat > state.txt Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh Apply following commands on state.txt: List Without ranges: $ cut -b 1,2,3 state.txt List with ranges : $ cut -b 1-3,5-7 state.txt $ cut -b 1- state.txt $ cut -b -3 state.txt $ cut -c 2,5,7 state.txt Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 8. Paste Command • Paste command is used to join files horizontally (parallel merging) by outputting lines consisting of lines from each file specified, separated by tab as delimiter, to the standard output. • When no file is specified, or put dash (“-“) instead of file name, paste reads from standard input and gives output as it is until a interrupt command [Ctrl-c] is given. • Syntax: paste [OPTION]... [FILES]... Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 9. $ cat > capital Itanagar Dispur Hyderabad Patna Raipur $ paste number state capital $ paste -d "|" number state capital 1|Arunachal Pradesh|Itanagar 2|Assam|Dispur 3|Andhra Pradesh|Hyderabad 4|Bihar|Patna 5|Chhattisgrah|Raipur Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg Example
  • 10. unmae & wget command $ uname • You can use the command to get the release number, version of Linux, and much more. • The “-a” flag is used to get detailed information. $ wget • You can use the wget command to download the content from the internet; • for instance, the following command will download VirtualBox. $ wget https://download.virtualbox.org/virtualbox/6.1.26/VirtualBox-6.1.26- 145957-Win.exe Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 11. apt-get or –apt command • Most important and most used commands of Ubuntu that works with Ubuntu Advanced Packaging Tool (APT); • You can use this “-apt-get” or “-apt” to install or remove packages • The “apt” requires sudo privileges to successfully execute the command. • Syntax : $ sudo apt install [packagename] • To install vlc media player package use • $ sudo apt install vlc • To remove package - $ sudo apt remove [packagename] Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 12. history command • The history command shows the list of commands (with numeric numbers) executed • $ history • One can execute any of the listed commands • If you want to execute the 2nd command (which is apt update command), then you have to write “!74” to get the result of that command: Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 13. ps command • ps - using the -ps command, you will be able to get the list of processes. $ ps Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 14. w command • W command will display the user details that are currently logged into the system • $ w Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 15. passwd • passwd - With the help of the passwd command, you can change the password of your Ubuntu user: • You must pass “username” to “passwd” to change the password of that; for example, the command given below will change the password of user “6cse01” Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 16. hostname command • This command will print your hostname on the terminal • $ hostname • bitlinux@6cse01 $ bitlinux Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 17. ping command • Ping - you can use the ping command to check the connectivity to your server; • for example, the command below will ping to YouTube and also prints the response time • $ping hostname or ip-address • $ ping youtube.com • $ ping google.com Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 18. $ uptime -shows how long system is running Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 19. $ users – shows username who are currently logged in Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 20. $ service – call and execute script Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg $ service --status-all
  • 21. $ ps – display about running process Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 22. kill, killall and pkill • kill terminates processes based on Process ID number (PID), • While the killall and pkill commands terminate running processes based on their names and other attributes. • Example $ ps PID TTY TIME CMD 11571 pts/20 00:00:00 bash 22166 pts/20 00:00:00 ps $ kill -s 0 11571 $ kill -s 0 11579 bash: kill: (11579) - No such process Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 23. $ pmap – memory map of process Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 24. $ free – shows memory status Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 25. $ netstat – display network status Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 26. $ nslookup – check domain name of ip info Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 27. $ route - list routing table for your server Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 28. ftp command • Here, ftp stands for File Transfer Protocol. This utility helps you upload and download your file from one computer to another computer. • $ftp hostname or ip-address • $ftp 172.16.0.100 • ftp> dir • ftp> get <filename> • ftp> quit • 221 Goodbye. • $ Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 29. More Commands • join • Tee • Comm • Cmp • Diff • tr Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 30. Text Editing with Vi Editor (vi- Visual Editor) Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 31. Vi Editor • The VI editor is a screen based editor used by many unix users. • It is the default editor that comes with the UNIX operating systems and is called vi (visual editor). • The improved version of vi is called the vim editor ( vi improved) is available with Linux systems. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 32. Modes of vi editor • There are three basic modes of vi:- 1. Command mode 2. Insert mode 3. Line mode Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 33. 1. Command mode:- • This the default when you enter vi. • In command mode - most letters, or short sequence of letters, that you type will be interpreted as commands, without explicitly pressing Enter. • If you press ESC when you’re in command mode, your terminal will beep at you. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 34. 2. Insert Mode • Insert mode:- In insert mode, whatever you type is inserted in the file at the cursor position. • Type i to enter insert mode from command mode; • press ESC to end insert mode, and return to command mode. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 35. 3. Line mode • Line mode:- Use line mode to enter line oriented commands. • To enter line mode from command mode, type a colon(:). • Your cursor moves to the bottom of the screen, by a colon prompt. • Type a line mode command and then press ENTER. • Each time you use a line mode command, you must • type a colon to enter line mode, • then type the command by the colon prompt at the bottom of the screen, • then press ENTER when you finish typing the command Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 36. Starting and stopping vi • To edit file $ vi generalnote • Above command starts vi and allocates a memory buffer for file generalnote • If the file already exists, text in the file will be displayed on the screen. • You can't add any text to the file until you go into insert mode because vi started in the command mode. • The tilde character (~) you see in the screen shot shows that the file has no text in these lines. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 37. Starting and stopping vi Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg • The tilde character (~) you see in the screen shot shows that the file has no text in these lines. • To switch to insert mode, press the i character • Press the Esc & : key to return to command mode. • To save file use :w command. • To quit the editor use :q command • Use : x or wq to save and quit in one step
  • 38. Cursor Movement Commands • The mouse does not move the cursor within the vi editor screen. You must have the key commands listed. • Before using any of these commands, make sure that you are in the command mode by pressing the ESC & : key. • You can also instruct the vi editor to display the line number with each line using the :set number command. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg Symbol Function l Move one character right h Move one character left j Move one line down k Move one line up < space > Move one character right G Go to last line of the file nG Go to line number n in the file $ Go to end of current line ^ Go to start of line w Go to beginning of next word b Go to beginning of previous word e Move to end of word H Go to first line of screen M Go to middle line of screen L Go to last line of screen ( Go to beginning of sentence ) Go to end of sentence { Go to beginning of paragraph } Go to end of paragraph
  • 39. Inserting text in vi Command Effect i Start inserting text at the current cursor location. I Start inserting text at the beginning of the current line. a Start inserting text at the next character position relative to the current cursor location. A Start inserting text at the end of the current line. o Append a blank line just below the current line and start inserting text from the beginning of that line. O Append a blank line just above the current line and start inserting text from the beginning of that line. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 40. Deleting text in vi Command Effect x Delete character at current cursor location. nx Delete n characters starting at current cursor location. X Delete previous character from the current cursor location. nX Delete n previous characters from the current cursor location. dd Delete current line. db Delete previous word. dw Delete from current cursor location to the end of word. dG Delete to the end of file including current line. Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 41. Text replacement command in vi Command Effect r Replace current character remaining in command mode s Replace current character and go to insert mode R Replace multiple characters until the key is pressed cw Change to the beginning of next word cc Change entire line cG Change to the end of file Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 42. Cut, Copy, and Paste Commands Command Effect yy Copy or yank current line nyy Copy n lines starting from current line position p Paste yanked text after the current cursor position P Paste yanked text before the current cursor position :m a Move current line and paste after line number a :a,bmc Move lines from a to b and paste after line number c :a,btc Copy lines from a to b and paste after line number c Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 44. What is in a shell script? • A shell script is a text file that contains a sequence of commands for a UNIX-based operating system. • Shell scripting is an important part of process automation in Linux. • Scripting helps you write a sequence of commands in a file and then execute them. • This saves you time because you don't have to write certain commands again and again Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 45. How to write shell script • Following steps are required to write shell script: • (1) Use any editor like vi or gedit to write shell script. • (2) After writing shell script set execute permission • (3) Execute shell script as • syntax: • bash shell-script-name • sh shell-script-name • ./your-script-name Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 46. First shell script echo "Our first script" echo "--------------------------------------------" echo # This inserts an empty line in output. echo "We are currently in the following directory" pwd echo "This directory contains the following files" ls Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 47. Prog1: Write following shell script, save it, execute it and note down the it's output. $ vi ginfo # # # Script to print user information who currently login , current date & time # clear echo "Hello $USER" echo "Today is c ";date echo "Number of user login : c" ; who | wc -l echo "Calendar" cal exit 0 Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 48. Prog 2 : Using if-else to check whether two numbers are equal a=10 b=20 if [ $a -eq $b ] then echo " Number is equal " else echo " number not equal " fi Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 49. C- Program in Linux Environment Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg
  • 50. First C Program Linux Laboratory - B.Tech. 6th CSE - Dr. D. P. Mishra, BIT Durg Steps: • Write program in vi editor • Save with .c extension • Comiple : $ gcc progname.c • Run ; $ ./a.out