Linux Unit 2
Linux Unit 2
There are advanced versions of the vi editor available, and the most
popular one is VIM which is Vi Improved. 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’s operation modes
They can be divided into two main parts.
*Command mode
*Insert mode
Command mode:
• The vi editor opens in this mode, and it only understands
commands
• In this mode, you can, move the cursor and cut, copy, paste the text
• This 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 is for inserting text 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
Starting the vi editor
Syntax :
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.
Note:
• You should be in the "command mode" to execute these
commands. VI editor is case-sensitive so make sure you type the
commands in the right letter-case.
• Make sure you press the right command otherwise you will end up
making undesirable changes to the file. You can also enter the insert
mode by pressing a, A, o, as required.
Moving within a file
•k - Move cursor up one line
•j - Move cursor down one line
•h - Move cursor left one character
•l - Move cursor right one character
•w - Move to the next word
•b - Move to the previous word
•$ - To the end of line
•0 - To the starting of line
•) - To the next sentence
•( - To the previous sentence
•} - To the next paragrah
•{ - To the previous paragrah
2. Type mformat a:
•The -R option opens the file in read-only mode using the Vi text editor.
•/var/log/messages is a system log file that contains messages from various
system services and applications.
•Displays information such as system startup messages, hardware
events, and software errors.
•Essential for monitoring system issues.
•Provides insights into system events and activities over time.
•Useful for troubleshooting errors and identifying security breaches.
•Allows users to review historical system logs for analysis and reporting.
• The -R option opens the file in read-only mode using the Vi text
editor.
•/proc/meminfo is a virtual file that provides detailed information
about the system's memory usage and statistics.
•Displays total available memory, free memory, and used memory.
•Includes information on memory usage by buffers and cache.
•Essential for monitoring system memory usage and diagnosing
performance issues.
•Helpful for system administrators and users to optimize memory
allocation and troubleshoot memory-related problems.
7. Vi –R /proc/mounts filesystems that are mounted.
At a time we can open several files but can view only one file.
Type :next to go to the next file
Backing Up and Restoring the File System
Steps: