We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15
vi Editor
• The default editor that comes with the
UNIX/LINUX operating system is called vi (visual editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can also use this editor to just read a text file. Syntax: • vi filename • Vi filename Modes of Operation in vi editor There are three modes of operation in vi: • Command Mode: When vi starts up, it is in Command Mode. This mode is where vi interprets any characters we type as commands and thus does not display them in the window. This mode allows us to move through a file, and to delete, copy, or paste a piece of text. To enter into Command Mode from any other mode, it requires pressing the [Esc] key. If we press [Esc] when we are already in Command Mode, then vi will beep or flash the screen. • Insert mode: This mode enables you to insert text into the file. Everything that’s typed in this mode is interpreted as input and finally, it is put in the file. The vi always starts in command mode. To enter text, you must be in insert mode. To come in insert mode you simply type i. To get out of insert mode, press the Esc key, which will put you back into command mode. • Last Line Mode(Escape Mode): Line Mode is invoked by typing a colon [:], while vi is in Command Mode. The cursor will jump to the last line of the screen and vi will wait for a command. This mode enables you to perform tasks such as saving files, executing commands. Moving within a File(Navigation): • To move around within a file without affecting text must be in command mode (press Esc twice). Here are some of the commands can be used to move around one character at a time. • Commands and their Description • k : Moves the cursor up one line. • j : Moves the cursor down one line. • h : Moves the cursor to the left one character position. • l : Moves the cursor to the right one character position. • 0 or | : Positions cursor at beginning of line. • $ : Positions cursor at end of line. • W : Positions cursor to the next word. • B : Positions cursor to previous word. • ( : Positions cursor to beginning of current sentence. • ) : Positions cursor to beginning of next sentence. • H : Move to top of screen. • M : Move to middle of screen. • L : Move to bottom of screen. • colon along with x : Colon followed by a number would position the cursor on line number represented by x. Editing and inserting in Files(Entering and Replacing Text): • To edit the file, we need to be in the insert mode. There are many ways to enter insert mode from the command mode. • i : Inserts text before current cursor location. • I : Inserts text at beginning of current line. • a : Inserts text after current cursor location. • A : Inserts text at end of current line. • o : Creates a new line for text entry below cursor location. • O : Creates a new line for text entry above cursor location. • r : Replace single character under the cursor with the next character typed. • R : Replaces text from the cursor to right. • s : Replaces single character under the cursor with any number of characters. • S :Replaces entire line. Copy and Past Commands • Copy lines or words from one place and paste them on another place by using the following commands. • Yy : Copies the current line. • 9yy : Yank current line and 9 lines below. • p : Puts the copied text after the cursor. • P : Puts the yanked text before the cursor. • Example Workflow: • Open a file: vim myfile.txt • Press i to enter Insert Mode and start editing. • Press Esc to return to Normal Mode. • Save your work: :w • Exit: :q SHell • In Red Hat, the default shell is usually Bash (Bourne Again SHell). Here’s a quick overview of using the shell in RHEL: Basic Shell Commands
• Navigating Directories:
• pwd: Print the current working directory.
• ls: List files and directories. • cd directory_name: Change to the specified directory. • cd ..: Move up one director • File Operations:
• touch filename: Create an empty file.
• mkdir directory_name: Create a new directory. • cp source_file destination: Copy a file. • mv source destination: Move or rename a file. • rm filename: Remove a file. • rmdir directory_name: Remove an empty directory. • Viewing File Content:
• cat filename: Display the contents of a file.
• less filename: View a file one screen at a time. • tail -n 10 filename: View the last 10 lines of a file. • head -n 10 filename: View the first 10 lines of a file. • Searching for Files:
• find /path -name filename: Search for a file by name.
• grep 'search_term' filename: Search for a specific term in a file. • System Information:
• top: Display running processes.
• df -h: Show disk space usage. • free -h: Show memory usage.