Editing text files from shell prompt - Managing running processes - Process
management - Lab:Monitoring process activity - Writing simple shell
scripts - Understanding shell scripts - Lab: Implementing basic shell
programs - Understanding server managing in RHEL - Install the server
RHEL - Lab: RHEL 8 Installation on virtual machine - Initial server
configuration - Lab: Configuring and verifying the initial server settings -
Remote server management - Lab: RHEL Remote server management -
Initial server configuration - Lab: Configuring and verifying the initial
server settings -Remote server management- Lab: RHEL Remote Server
management - File Transfer - Lab: Securely coping files between Servers -
Log Management - Lab1: Monitoring system logs - Lab2: Recording and
managing server logs – Server monitoring - Lab: Monitoring the health of
the server.
Editing Text Files from Shell Prompt
Introduction
In Linux, text files are widely used for configuration settings, scripts, and
documentation. Editing these files directly from the shell prompt is a
fundamental skill for system administrators and developers. Linux provides
several text editors such as vi, vim, nano, and gedit to modify text files
efficiently.
Text Editors in Linux
Linux provides different types of text editors:
1. Command-Line Editors
o vi (Visual Editor)
o vim (VI Improved)
o nano (User-friendly and simple)
o ed (Basic line editor)
2. Graphical Editors
o gedit (GNOME default editor)
o kate (KDE text editor)
o leafpad (Lightweight editor)
Among these, vi/vim and nano are the most commonly used editors in server
environments.
,Using Nano Editor
The nano editor is simple and beginner-friendly. It provides on-screen shortcuts
for ease of use.
Opening a File
nano filename.txt
If the file does not exist, nano creates a new file.
Basic Commands in nano
Ctrl + O → Save file
Ctrl + X → Exit editor
Ctrl + K → Cut text
Ctrl + U → Paste text
Ctrl + W → Search text
Ctrl + G → Show help menu
Using Vi and Vim Editors [ Use our png image for detailed explanation]
The Vi and vim editors are powerful and widely used.
Opening a File
vi filename.txt
Modes in vi
vi operates in three different modes:
1. Command Mode: Default mode for executing commands.
2. Insert Mode: Allows editing of text.
3. Visual Mode: Used for selecting and manipulating text.
Switching Between Modes
Enter Insert Mode: Press i, a, o
Exit Insert Mode: Press Esc
Enter Command Mode: Press Esc
Basic Commands in vi
Command Description
, :w Save file
:q Quit editor
:wq Save and quit
:q! Quit without saving
yy Copy line
dd Delete line
p Paste line
/text Search text
Editing a File
Adding Text
1. Open the file with vi filename.txt
2. Press i to enter insert mode
3. Type the required text
4. Press Esc to switch to command mode
5. Type :wq to save and exit
Searching Text
Use /word in command mode to search a specific word.
/hostname
Press n to jump to the next occurrence.
Practical Example
Create a configuration file and edit it using vi:
vi /etc/myconfig.conf
1. Press i and add:
server_name=LinuxServer
port=8080
directory=/var/www/html
2. Press Esc and save with :wq
3. Verify using cat /etc/myconfig.conf
Lab Exercise