VI Editor
VI Editor
VI Editor
There are many ways to edit files in Unix. Editing files using the screen-oriented text
editor vi is one of the best ways. This editor enables you to edit lines in context with
other lines in the file.
An improved version of the vi editor which is called the VIM has also been made
available now. Here, VIM stands for Vi IM proved. Some of the other ones are Elvis, Nvi,
Nano, and Vile. It is wise to learn vi because it is feature-rich and offers endless possibilities to edit
a file.
vi is generally considered the de facto standard in Unix editors because −
It's usually available on all the flavors of Unix system.
Its implementations are very similar across the board. It works the same across
different platforms and Distributions
It requires very few resources.
It is more user-friendly than other editors such as the ed or the ex.
You can use the vi editor to edit an existing file or to create a new file from scratch.
You can also use this editor to just read a text file.
1 vi filename
Creates a new file if it already does not exist, otherwise opens an existing file.
2 vi -R filename
Opens an existing file in the read-only mode.
3 view filename
Opens an existing file in the read-only mode.
Following is an example to create a new file testfile if it already does not exist in the
current working directory −
$vi testfile
The above command will generate the following output −
|
~
~
~
~
~
~
~
~
~
~
~
~
"testfile" [New File]
You will notice a tilde (~) on each line following the cursor. A tilde represents an
unused line. If a line does not begin with a tilde and appears to be blank, there is a
space, tab, newline, or some other non-viewable character present.
You now have one open file to start working on. Before proceeding further, let us
understand a few important concepts.
Operation Modes
While working with the vi editor, we usually come across the following two modes −
Command mode − This mode enables you to perform administrative tasks such
as saving the files, executing the commands, moving the cursor, cutting
(yanking) and pasting the lines or words, as well as finding and replacing. In this
mode, whatever you type is interpreted as a command. The vi editor opens in this
mode, and it only understands commandsIn this mode, you can, move the cursor and cut, copy,
paste the textThis mode also saves the changes you have made to the file Commands are case
sensitive. You should use the right letter case.
Insert mode − This mode enables you to insert text into the file. Everything that's
typed in this mode is interpreted as input and placed in the file. You can switch to
the Insert mode from the command mode by pressing ‘i’ on the keyboard, Once you are in
Insert mode, any key would be taken as an input for the file on which you are currently
working.To return to the command mode and save the changes you have made you need to
press the Esc key
vi always starts in the command mode. To enter text, you must be in the insert mode
for which simply type i. To come out of the insert mode, press the Esc key, which will
take you back to the command mode.
Hint − If you are not sure which mode you are in, press the Esc key twice; this will take
you to the command mode. You open a file using the vi editor. Start by typing some
characters and then come to the command mode to understand the difference.
Getting Out of vi
The command to quit out of vi is :q. Once in the command mode, type colon, and 'q',
followed by return. If your file has been modified in any way, the editor will warn you of
this, and not let you quit. To ignore this message, the command to quit out of vi without
saving is :q!. This lets you exit vi without saving any of the changes.
The command to save the contents of the editor is :w. You can combine the above
command with the quit command, or use :wq and return.
The easiest way to save your changes and exit vi is with the ZZ command. When
you are in the command mode, type ZZ. The ZZ command works the same way as
the :wq command.
If you want to specify/state any particular name for the file, you can do so by specifying
it after the :w. For example, if you wanted to save the file you were working on as
another filename called filename2, you would type :w filename2 and return.
1 k
Moves the cursor up one line
2 j
Moves the cursor down one line
3 h
Moves the cursor to the left one character position
4 l
Moves the cursor to the right one character position
Editing Files
To edit the file, you need to be in the insert mode. There are many ways to enter the
insert mode from the command mode −
O-Creates a new line for text entry above the cursor location
o-Creates a new line for text entry below the cursor location
A-Inserts text at the end of the current line
a-Inserts text after the current cursor location
I-Inserts text at the beginning of the current line
i-Inserts text before the current cursor location
I — Insert at cursor (goes into insert mode)
C — Delete contents of line after the cursor and insert new text. Press esc key to end insertion.
cw — Change word
r — Replace character
Control Commands
The following are useful commands which you can use along with Control Key.
Deleting Characters
Here is a list of important commands, which can be used to delete characters and lines
in an open file −
1 X
Deletes the character under the cursor location
2 X
Deletes the character before the cursor location
3 Dw
Deletes from the current cursor location to the next word
4 d^
Deletes from the current cursor position to the beginning of the line
5 d$
Deletes from the current cursor position to the end of the line
6 D
Deletes from the cursor position to the end of the current line
7 Dd
Deletes the line the cursor is on
Change Commands
You also have the capability to change characters, words, or lines in vi without deleting
them. Here are the relevant commands −
1 Cc
Removes the contents of the line, leaving you in insert mode.
2 Cw
Changes the word the cursor is on from the cursor to the lowercase w end of the
word.
3 R
Replaces the character under the cursor. vi returns to the command mode after
the replacement is entered.
4 R
Overwrites multiple characters beginning with the character currently under the
cursor. You must use Esc to stop the overwriting.
5 S
Replaces the current character with the character you type. Afterward, you are
left in the insert mode.
6 S
Deletes the line the cursor is on and replaces it with the new text. After the new
text is entered, vi remains in the insert mode.
1 Yy
Copies the current line.
2 Yw
Copies the current word from the character the lowercase w cursor is on, until the
end of the word.
3 P
Puts the copied text after the cursor.
4 P
Puts the yanked text before the cursor.
Advanced Commands
There are some advanced commands that simplify day-to-day editing and allow for
more efficient use of vi −
Given below is the list advanced commands.
1 ^
Searches at the beginning of the line (Use at the beginning of a search
expression).
2 .
Matches a single character.
3 *
Matches zero or more of the previous character.
4 $
End of the line (Use at the end of the search expression).
5 [
Starts a set of matching or non-matching expressions.
6 <
This is put in an expression escaped with the backslash to find the ending or the
beginning of a word.
7 >
This helps see the '<' character description above.
The character search searches within one line to find a character entered after the
command. The f and F commands search for a character on the current line
only. f searches forwards and F searches backwards and the cursor moves to the
position of the found character.
The t and T commands search for a character on the current line only, but for t, the
cursor moves to the position before the character, and T searches the line backwards
to the position after the character.
Set Commands
You can change the look and feel of your vi screen using the following :set commands.
Once you are in the command mode, type :set followed by any of the following
commands.
Sr.No Command & Description
.
1 :set ic
Ignores the case when searching
2 :set ai
Sets autoindent
3 :set noai
Unsets autoindent
4 :set nu
Displays lines with line numbers on the left side
5 :set sw
Sets the width of a software tabstop. For example, you would set a shift width of
4 with this command — :set sw = 4
6 :set ws
If wrapscan is set, and the word is not found at the bottom of the file, it will try
searching for it at the beginning
7 :set wm
If this option has a value greater than zero, the editor will automatically "word
wrap". For example, to set the wrap margin to two characters, you would type
this: :set wm = 2
8 :set ro
Changes file type to "read only"
9 :set term
Prints terminal type
10 :set bf
Discards control characters from input
Running Commands
The vi has the capability to run commands from within the editor. To run a command,
you only need to go to the command mode and type :! command.
For example, if you want to check whether a file exists before you try to save your file
with that filename, you can type :! ls and you will see the output of ls on the screen.
You can press any key (or the command's escape sequence) to return to your vi
session.
Replacing Text
The substitution command (:s/) enables you to quickly replace words or groups of
words within your files. Following is the syntax to replace text −
:s/search/replace/g
The g stands for globally. The result of this command is that all occurrences on the
cursor's line are changed.
vi <filename_NEW> or <filename_EXISTING>
And if you specify an existing file, then the editor would open it for you to edit. Else, you can create a
new file.
Saving and Closing the file
Shift+zz – Save the file and quit
:w – Save the file but keep it open
:q – Quit without saving
:wq – Save the file and quit
:q! Quit discarding changes made
:w! Save (and write to non-writable file)
:w fname Save as fname
You should be in the command mode to exit the editor and save changes to the file.
aaa
bbb
ccc
Then delete the second line with the vi dd command, you can then undo this
change by typing the letter u while still in command mode. This undo
command works with other changes as well, including inserts, deletes, search
and replace functions, etc.
Update: As noted in the Comments section below, the best way to redo a vim
command is to use the [Ctrl][r] keystroke.
Another approach to redo a command in vi/vim is to enter the “redo”
command in last-line mode, like this:
:redo
For instance, if you wanted to again delete that second line, you could type this
command to re-do that change. But again, since learning about it, the [Ctrl]
[r] keystroke is a much faster way to undo a change in vim.
Joe Editor
• JOE is a full featured terminal-based screen editor which is distributed under the GNU
General Public License (GPL)
• JOE is written in C and its only dependency is libc
Features
• Line number mode displays line number of each line.
• Auto-indent mode.
• Block move/copy/delete/filter
• STARTING JOE: Joe can be started from the menu. Alternatively, from the Unix shell,
type joe <filenames>
• MOVING: Movement by a single line or character is accomplished by pressing the arrow
keys. Hitting `^U' will scroll upwards one screen, and hitting `^V' will scroll downwards
one screen. Hitting `^K L' will allow you to jump to a specific line number within the file.
• SEARCHING: To search for a certain text string, type `^K F'. You will first be prompted
for the string for which to search, and then any other search options (such as case
insensitivity, search direction, etc.). To repeat the most recent search, type `^L'.
• BLOCK OPERATIONS: To delete a single character, type <Backspace> or <Del>. To
delete an entire line, type `^Y'. Joe also supports block editing. To mark the beginning of a
block, type `^K B'. To mark the end, type `^K K'. To delete a selected block, type `^K Y'.
To move the block to the current cursor location, type `^K M'. To copy the block to the
current cursor location, leaving the original block where it is, type `^K C'.
• UNDO / REDO: Joe remembers all changes made to the file and allows you to undo or redo
any changes you make. To undo the most recent change, type `<Ctrl>-<Shift>-_' (control-
underline). To redo an undone change, type `<Ctrl>-<Shift>-^' (control-caret).
• EXITING JOE: To exit joe and save changes to the current file, type `^K X'. To exit joe
without saving any changes, type `^C'. If any changes were made, you will be asked if
you're sure you want to quit before joe actually exits.
Package Management
• Package management is a method of installing and maintaining software on the system.
• Today, most people can satisfy all of their software needs by installing packages from
their Linux distributor.
• This contrasts with the early days of Linux, when one had to download and compile
source code in order to install software.
• Not that there is anything wrong with compiling source code; in fact, having access to
source code is the great wonder of Linux. It gives us (and everybody else) the ability to
examine and improve the system.
• It's just that having a pre-compiled package is faster and easier to deal with.
Packaging Systems
• Different distributions use different packaging systems and as a general rule, a package
proposed for one distribution is not compatible with another distribution.
• Most distributions fall into one of two camps of packaging technologies: the Debian
“.deb” camp and the Red Hat “.rpm” camp. There are some important exceptions such as
• Gentoo, Slackware, and Foresight, but most others use one of these two basic systems.
Style Command(s)
Debian apt-get update
apt-get install package_name
Red Hat yum install package_name
Installing A Package From A Package File
If a package file has been downloaded from a source other than a repository, it can be installed
directly (though without dependency resolution) using a low-level tool.
Style Command(s)
Debian dpkg --install package_file
Red Hat rpm -i package_file
Installing A Package From A Package File
Example: If the emacs-22.1-7.fc7-i386.rpm package file had been downloaded from a non-
repository site, it would be installed this way:
rpm -i emacs-22.1-7.fc7-i386.rpm
Removing A Package
Packages can be uninstalled using either the high-level or low-tools. The high-level tools are
shown below.
Style Command(s)
Debian apt-get remove package_name
Red Hat yum erase package_name
Example: To uninstall the emacs package from a Debian-style system:
apt-get remove emacs
Updating Packages From A Repository
The most common package management task is keeping the system up-to-date with the latest
packages. The high-level tools can perform this vital task in one single step.
Style Command(s)
Debian apt-get update; apt-get upgrade
Red Hat yum update
Example: To apply any available updates to the installed packages on a Debian-style
system:
apt-get update; apt-get upgrade
Upgrading A Package From A Package File
If an updated version of a package has been downloaded from a non-repository source, it can be
installed, replacing the previous version:
Style Command(s)
Debian dpkg --install package_file
Red Hat rpm -U package_file
Example: Updating an existing installation of emacs to the version contained in the
package file emacs-22.1-7.fc7-i386.rpm on a Red Hat system:
rpm -U emacs-22.1-7.fc7-i386.rpm
Listing Installed Packages
These commands can be used to display a list of all the packages installed on the system:
Style Command(s)
Style Command(s)
Debian dpkg --status package_name
Red Hat rpm -q package_name
Example: To determine if the emacs package is installed on a Debian style system:
dpkg --status emacs
Displaying Info About An Installed Package
If the name of an installed package is known, the following commands can be used to display a
description of the package:
Style Command(s)
Debian apt-cache show package_name
Style Command(s)
Debian dpkg --search file_name
Red Hat rpm -qf file_name
Example: To see what package installed the /usr/bin/vim file on a Red Hat system:
rpm -qf /usr/bin/vim
Finding A Package In A Repository
Using the high-level tools to search repository metadata, a package can be located based on its
name or description.
Style Command(s)
Debian apt-get update
apt-cache search search_string
Red Hat yum search search_string
What is a package manager in Linux?
In simpler words, a package manager is a tool that allows users to install, remove,
upgrade, configure and manage software packages on an operating system. The
package manager can be a graphical application like a software center or a command
line tool like apt-get or pacman.
It involves configuring monitoring and possibly reconfiguring components in a network with the goal of providing
optimal performance, minimum downtime, proper security, accountability and flexibility.
Features
Network automation
One defining feature of a modern network management system is network automation. This is the procedure of
automating the configuring, handling, testing, deploying, and operating of physical and virtual devices inside a
network. Network service availability increases when everyday network tasks and functions are automated and
repetitive processes are controlled and managed automatically.
Network administration
Network administration encompasses tracking network resources, including switches, routers, and servers. It also
includes performance monitoring and software updates.
Network Operation
This contains smooth network functioning as created and intended, including close monitoring of activities to quickly
and effectively address and fix problems as they occur and preferably even before users are aware of the problem.
Network assurance
Network assurance features are often included in modern network management systems. These features help
improve network performance, customer experience, and security. Assurance systems help network analytics,
application analytics, and policy analytics, as well as AI and ML, to achieve full network assurance.
Network provisioning
Network provisioning involves network resource configuration for the purposes of supporting any given service, like
voice functions or accommodating additional users.
Network maintenance
Network maintenance covers upgrades and fixes to network resources. It also consists of proactive and remediation
activities executed by working with network administrators, such as replacing network gear like routers and switches.
Network analytics
Network analytics is a software tool that compares incoming information against preprogrammed operational models
and makes functional decisions for improving network performance.
Virtual hosting is a method for hosting multiple domain names (with separate handling of each
name) on a single server (or pool of servers).[1] This allows one server to share its resources, such as
memory and processor cycles, without requiring all services provided to use the same host name.
The term virtual hosting is usually used in reference to web servers but the principles do carry over
to other Internet services.
There are two main types of virtual hosting, name-based and IP-based. Name-based virtual hosting uses the host
name presented by the client.Port-based virtual hosting is also possible in principle but is rarely used in practice
because it is unfriendly to users.
Name-based
Name-based virtual hosts use multiple host names for the same IP address. Name-based virtual hosting uses the
host name presented by the client. This saves IP addresses and the associated administrative overhead but the
protocol being served must supply the host name at an appropriate point. In particular, there are significant difficulties
using name-based virtual hosting with SSL/TLS.
IP-based
When IP-based virtual hosting is used, each site (either a DNS host name or a group of DNS host names that act the
same) points to a unique IP address. The webserver is configured with multiple physical network interfaces, virtual
network interfaces on the same physical interface or multiple IP addresses on one interface. The web server can
either open separate listening sockets for each IP address, or it can listen on all interfaces with a single socket and
obtain the IP address the TCP connection was received on after accepting the connections. Either way, it can use the
IP address to determine which website to serve. The client is not involved in this process and therefore (unlike with
name-based virtual hosting) there are no compatibility issues.
Port-based[edit]
The default port number for HTTP is 80. However, most webservers can be configured to operate on almost any port number,
provided the port number is not in use by any other program on the server. There is the HTTP Secure special port 443 that needs
special configuration (see Server Name Indication). Port based web sites are explicitly bound to a unique port number and an IP
address. In this case the IP address is used for hosting multiple web sites. The unique port number used for a common IP address
distinguish an individual web site from other web sites bound to the same IP Address.
IIS Services
Internet Information Services is a general-purpose web server from Microsoft. It runs on a Windows
system and provides the user with the requested set of webpages or files. IIS protocols form the basics of
internet information services. The function of a web server is to approve requests from various client
computers to return the required response. It enables web servers to deliver the transfer information
across an array of Local Area Networks (LANs) including corporate intranets. It has the ability to share
information with the user in numerous forms such as text documents, HTML webpages, and images.
It works using a wide range of protocols and languages. To create text buttons and image placements, HTML is
used extensively. The HTTP (Hyper Text Transfer Protocol) acts as the basic protocol in order to transfer
information from the web server to the user. On the other hand, the File Transfer Protocol (FTP) is used to
transfer files.
Further, the Secure Sockets Layer (SSL) Protocol, developed by Netscape in order to transfer documents
through the internet, has a cryptographic system that puts to use a couple of keys to undertake data
encryption.
IIS not only includes all the essential features for the website to be hosted, it also supports extensions that add
extra functionalities to the server. For instance, the WinCache allows the PHP script to run much faster by
caching the processes of the PHP. The URL Rewrite Model enables webmasters to publish pages having friendly
URLs. These pages make it easier for the user to type and remember these friendly URLs.
IIS is a go-to option for commercial websites as it offers several advanced features that are backed by
Microsoft. However, a commercial license is required for using it. Its price can witness a rise depending on the
number of users. Therefore, the open-source and free-for-all Apache HTTP Server remains the most widely-
used web server software.
The IIS Manager is used for configuring the features of the IIS
The File Transfer Protocol allows the user to upload and download files
Webpage isolation is used to prevent one website from interfering with other websites on the user’s server
It is also used to configure web applications that are developed using a wide range of programming languages
PHP, Python, and ASP.NET
The Windows PowerShell can be used for undertaking a majority of administrative tasks for your web server
The cost of the deployment / user gets reduced with the use of IIS. The final users (end users) of an IIS
application can run it via a browser. A user doesn’t require to install a specialized software on his computer in
order to run the application
IIS applications work with a multitude of browsers and Operating Systems (OS). It gives the user an opportunity
to reach a wide audience
The framework of active server pages gives the user an object model which enables the user to manipulate
forming the core of the IIS. Furthermore, it allows the user to undertake data retrieval from a browser
Once a web class has been created, it can easily be accessed in a separate web class
Unlike scripting, your code isn’t embedded in the HTML document. The process of developing and designing the
application or website’s User Interface can be separated from writing and debugging its code
The state between a client and the server can be managed using a database or an object
IIS is one of the server roles on Windows Server 2012 R2, named Web Server (IIS). You
can use the following to install IIS:
When the Web Server (UI) role is chosen for the first time in the Add Roles and
Features Wizard in Server Manager, the basic components and services needed for IIS
are automatically selected. The following procedure will install Internet Information
Services on a running physical server when IIS has not already been installed. To change
an existing installation of IIS, perform the next procedure, Install additional role services
for IIS. These two procedures involve different steps.
9. On the Features page, select any features that you would like to install, and then
click Next. Note that you do not need to select any features on this page to install
IIS. IIS setup will select the features that are required.
11. On the Role Services page, select any additional role services that you want to
install.
You can also deselect role services that were selected by default when you
selected Web Server. However, at least one role service must be selected for Web
Server to be selected and installed.
12. If you selected a role service that requires other role services or features to be
installed, a page will be opened indicating the role services or features to be
installed. Leave Include management tools (if applicable) selected to select the
install management tools associated with the server role. You may not need the
management tools on the destination server if you plan to manage the role
remotely. Click Add Features to add the required role services or features.
13. After you have added the role services that you need on the Role Services page,
click Next.
14. On the Confirmation page, verify the role services and features that are selected.
Select Restart the destination server automatically if required to restart the
destination server if the settings need to take immediate effect. To save the
configuration information to an XML-based file that you can use for unattended
installations with Windows PowerShell, select Export configuration settings,
move to the appropriate path in the Save As dialog box, enter a file name, and
then click Save.
16. On the Results page, verify that the installation succeeds, and then click Close.
17. Confirm that the Web server works by opening a Web browser, and verifying that
the following default Web page is displayed when you use
the http://localhost address.