Linux Professional Institute LPIC-1 Exam 101

GNU and Unix Commands

Basic File Editing vi

Managing and editing text files is a core skill for any Linux user. This guide covers:

  • Viewing logs and files with the less and more pagers
  • Performing quick edits in Vim (Vi IMproved)
  • Verifying your changes after saving

The less pager provides powerful navigation and search features:

less /var/log/dnf.log
  • Scroll up/down with and or PgUp/PgDn
  • The filename appears at the bottom left
  • Quit with q

Searching Inside less

ActionCommand
Search forward (case-sensitive)/debug
Jump to next matchn
Toggle case-insensitive matching inline-i
Start less in case-insensitive modeless -i /var/log/dnf.log
Jump to previous matchN

Note

You can enable case-insensitive search at any time by typing -i inside less.


Paging with more

A simpler alternative, more advances one screen at a time:

more /var/log/dnf.log
  • Spacebar: Next page
  • Enter: Next line
  • q: Quit

Note

For large files or complex searches, less is generally preferred over more.


Getting Started with Vim

Vim is a modal editor: it has Normal, Insert, and Command modes.

vim

On launch without a filename, you'll see:

VIM - Vi IMproved 8.0.1763 by Bram Moolenaar et al.
Modified by <[email protected]>
type :help<Enter> or <F1> for on-line help
type :q<Enter> to exit

Switching to Insert Mode

  • Press i to enter Insert Mode (-- INSERT -- appears)
  • Type your content
  • Press Esc to return to Normal Mode

Essential Vim Commands

CommandModeDescription
iNormalSwitch to Insert Mode
/patternNormalSearch forward for “pattern”
\cNormalToggle case-insensitive search
yyNormalYank (copy) current line
ddNormalDelete (cut) current line
pNormalPaste after the cursor
:3NormalGo to line 3
:wCommandSave (write) the buffer
:wqCommandSave and quit
:q!CommandQuit without saving changes

Warning

Unsaved changes will be lost if you use :q!. Always use :w or :wq to preserve your edits.

Saving Your Work

:w

The image shows a terminal window with text being edited in a text editor, likely Vim, with the command `:w` at the bottom. The text reads "This is our text for our vim demo."


Comparing less vs more

PagerUsageNavigationQuit
lessless FILE↑/↓, PgUp/PgDnq
moremore FILESpacebar, Enterq

Verifying Your Edits

After saving a file (e.g., testfile), confirm the contents:

cat testfile

Example output:

no yes no
yes
no
no
no
no
yes
new changes

Further Reading

Watch Video

Watch video content

Previous
Search Text Files Using Regular Expressions Part 1 Understand the differences between basic and extended regular expressions