Most popular web site - 73Chapter 2Running Commands from the Shell .Ctrl+F Page ahead,

73Chapter 2Running Commands from the Shell .Ctrl+F Page ahead, one page at a time. .Ctrl+B Page back, one page at a time. .Ctrl+D Page ahead 1/2 page at a time. .Ctrl+U Page back 1/2 page at a time. .G Go to the last line of the file. .1G Go to the first line of the file. (Use any number to go to that line inthefile.) Searching for TextTo search for the next occurrence of text in the file, use either the slash (/) orthequestion mark (?) character. Follow the slash or question mark with a pattern(string of text) to search forward or backward, respectively, for that pattern. Withinthe search, you can also use metacharacters. Here are some examples: ./hello Searches forward for the word hello. .?goodbye Searches backward for the word goodbye. ./The.*foot Searches forward for a line that has the word Thein it andalso, after that at some point, the word foot. .?[pP]rint Searches backward for either printor Print.Remember that casematters in Linux, so make use of brackets to search for words that could havedifferent capitalization. The vi editor was originally based on the ex editor, which didn t let you work in full-screen mode. However, it did enable you to run commands that let you find andchange text on one or more lines at a time. When you type a colon and the cursorgoes to the bottom of the screen, you are essentially in ex mode. Here is an exampleof some of those ex commands for searching for and changing text. (I chose thewords Localand Remoteto search for, but you can use any appropriate words.) .:g/Local Searches for the word Localand prints every occurrence of thatline from the file. (If there is more than a screenful, the output is piped to themorecommand.) .:s/Local/Remote Substitutes Remotefor the word Localon the current line. .:g/Local/s//Remote Substitutes the first occurrence of the word Localon every line of the file with the word Remote. .:g/Local/s//Remote/g Substitutes every occurrence of the word Localwith the word Remotein the entire file. .:g/Local/s//Remote/gp Substitutes every occurrence of the word Localwith the word Remotein the entire file and then prints each line so that youcan see the changes (piping it through moreif output fills more than one page).

Leave a Reply