RH124 Ch 5: Creating and Editing Text Files

Almost all Linux configuration is plain text, so you must be quick and accurate in an editor. Vim is always present on RHEL; nano is easier but may not be installed everywhere.

Vim survival kit - Vim starts in command mode. Press i to insert, Esc to return. - :w save, :q quit, :wq (or ZZ) save and quit, :q! quit without saving. - dd delete a line, yy copy, p paste, u undo, Ctrl+R redo. - /text search, n next match, :set nu line numbers, G last line, gg first line. - :%s/old/new/g replace everywhere; :g/^/d delete all lines starting with . - vimtutor is a 30-minute built-in course worth doing once.

Without an editor - echo 'line' file appends one line. - A here-document writes several: cat file <<'EOF' … EOF. - sed -i 's/old/new/g' file edits in place; sed -i '/^/d' file deletes comment lines.

Viewing: cat, less (scroll, / to search), head -n 5, tail -n 20, tail -f to follow a growing log.

Shell start-up files: ~/.bashrc runs for each interactive shell, ~/.bashprofile at login (and it reads .bashrc). Put personal aliases, umask and variables like export EDITOR=vim there; system-wide settings go in /etc/profile.d/.sh.

Common mistakes: editing a file in the wrong place (check the path), leaving vim with :q! and losing work, and forgetting export so a variable is not passed to programs.