logo © 1996 Phil Waclawski
Felitaur Site
Offerings
About Me
Crafts
Services
ftp files
Help Files
What's New?
Home Page
Other Links
Anatomy &
Physiology
Arthropods
Biology
Computers
Ferrets
Fun Links
Internet
Linux
S.C.A.
Win 95/NT
Comments or
Suggestions
webmaster@ felitaur.com
   
File Manipulation and Maintenance
Lecture Overview Index | Linux SysAdmin Homepage
Overview
Goals:
  • How to view and edit files
  • How to use the standard vi editor
  • How to locate files
  • The power of the "rm" command
The following programs/files/directories will be discussed for this topic:
  • cat
  • more or less
  • pico
  • vim
    VIM Short list of commands
    Text Entry Modes
    i or I Insert text at cursor (i) or at beginning of line (I)
    a or A Append text after cursor (a) or at end of line (A)
    o or O Open a new line after the current one (o) or before the current line (O)
    For any of the commands below, you can make sure you are in command mode by hitting the [ESC] key
    Save,quit,Edit, Load Files
    :w {filename} write out current file (w) or save file as (:w filename)
    :wq or :q! write out and quit (wq) or quit without saving (:q!)
    :w {filename} write out current file (w) or save file as (:w filename) NOTE, the save as will NOT switch you to the newly named file
    :save filename save file to name, and switch to that file for editing
    :edit filename lets you open existing filename, or a new buffer of that name
    :r filename lets you "read" a file into the current cursor position (effectively pasting the file into your present file)
    For all of the above, putting a space after the command letter, and then hitting [tab] will let you go through files in your pwd, or if you put the first letter of what you want, just files that start with that letter.
    Basic Editing commands
    dd
    3dd
    "t4dd
    D
    dgg
    dG
    Delete line at cursor (and saves it to "clipboard")
    Delete line at cursor and next 2 (can use any number not just 3)
    Delete 4 lines and save them in buffer t
    Delete from cursor to END of line
    Delete from cursor to TOP of the File
    Delete from cursor to Bottom of the File
    yy
    3yy
    "t4yy
    ygg
    yG
    p
    "tp
    copy (yank) line at cursor
    copy (yank) 3 lines
    copy 4 lines into the buffer t can use letters a-z
    copy from cursor to TOP of the File
    copy from cursor to BOTTOM of the File
    Paste most recent copy or delete
    Paste buffer t
    :reg show all present paste buffers and contents
    visual editing mode
    v start visual edit mode, which allows you to select text by moving cursor with arrow keys or hjkl
    d
    y
    "ty
    "td
    delete highlighted text
    copy (yank) highlighted text
    copy hightlighted text to buffer t
    Delete highlighted text and store in buffer t
    >
    <
    3>
    >}
    Indent visually highlighted code one "tab"
    Un-Indent Code one "tab" level
    Indent highlighted text 3 "tab" levels
    Indent from cursor to next blank line
    There is no "number" option for visual mode, as it only works on the highlighted text, or by using shortcuts to jump to particular characters
    Split Windows and Tabs
    :split
    :vsplit
    ctrl-ww
    split screen horizontally (can use :edit to open new file in split screen)
    split screen vertically
    (hit control-w and then w) to switch between windows
    :tabnew
    :tabn
    :tabp
    create new tab (remember :edit to load new content into tab)
    move to next tab
    move to previous tab
    Folding Sections
    zf%
    zo
    zc
    close a fold at cursor based on characters (such as from { to closing }
    open fold at cursor
    close fold at cursor
    Saving Sessions (with all your folds, tabs, split screens)
    :mksession name.vim
    vim -S name.vim
    :source name.vim
    :wall
    :qall
    create a session of name.vim that has your present tab/splits/folds
    load session name.vim (with splits, folds, tabs and files) when you start vim
    load a session name.vim after opening vim
    save all tabs/windows
    quit all (as :q will JUST quit that tab/window)
    May need to add the following line to your .vimrc file
    set sessionoptions=blank,buffers,curdir,folds,globals,help,localoptions,options,resize,tabpages,winsize,winpos
    • /  ?  (n or N) and then . for repeat replacement
    • :1,$s/arizona/arizona/gi
    • :set number (nu),:set nonumber, :set cindent (cin) for c style indents
    • :set autoindent (ai, noai), :set shiftwidth=4
    • :set tabstop=4
    • :syntax enable (vim on by default)
    • noremap <F4> :set hlsearch! hlsearch?<CR>
    • .vimrc (create this file in your home directory, and just remove the : from the above settings when you type them into this file,
      so set number NOT :set number
    • ^n or ^p for tab completion
    • Does have a macro set up (qa to record macro to register a)
      (@a to "play" macro a), just repeats keystroke commands
  • find
  • which
  • whereis
  • locate (need to run updatedb as root for this to be available for users)
  • rm
Questions
cat vs. more vs. less
  • Why don't you normally use cat to view files anymore?
  • Why is cat still around?
  • What are the differences between more and less?
  • How do you back up in more or less?
  • How do you get OUT of more or less?
  • Which text viewer do the man pages use by default?
vi questions
  • How do you open a text file with vi?
  • What is the difference between text mode and command mode?
  • What key do you hit to enter command mode?
  • How do you save in vi?
  • How do you quit and save, or quit and not save?
  • How do you delete a line? 5 lines? A single character?
  • To switch to text mode, you can type a i A I (amongst others), how are those four characters different?
  • How do you cut and paste in vi? How about copy and paste?
  • How do you search for a word?
  • How do you insert an external file?
  • How would you change all instances of Arizona and Ariz. to AZ for an entire document?
  • what happens when you place the cursor over a { } or ( ) when there are matched pairs of them? (note, a vim not vi feature)
pico questions
  • What is pico actually designed to do?
  • What is nano?
  • Why will many system administrators laugh at you if you mention pico?
  • What is the default editor on nearly every flavor of UNIX?
  • How do you save in pico?
  • How do you delete lines, characters?
  • How do you "cut" and "paste" in pico?
  • How do you search in pico?
  • How do you insert an external file?
  • Does pico have any advanced editing capabilities?
find, which and locate questions
  • If you just want to find where a command is located, the which command is the easiest to use, assuming what?
  • locate is a spammy search command? Explain.
  • how are whereis and which similar? different? What are some of the options for whereis ?
  • find is the default search tool on the system, explain how to do the following
    • Find a file called ugh.jpg that is somewhere in the /home directory.
    • Find all files that belong to the user pwa.
    • How would you use find to find all files ending in .bak and then run the command mv ~/tmp ?
    • What does find . -name "*.html" -exec chmod 644 '{}' \; do?
rm questions
  • Why is it a good idea to use the -i option, especially if you are root?
  • Is there an undo option for rm?
  • How do you delete a directory and all sub directories within?
  • Why should you NEVER type rm -r / , especially as root?
  • If you have the -i option set by default (say for root in redhat), how could you override it?
  • How do you delete files with strange characters in the name?
Activities & Assignments
  • Create a file called "test" using pico. Type a few lines. Try and cut and paste lines, correct words, search, and save.
  • Now, open up the same file in vi, and do the same.
  • Try out this in vi :%s/term1/term2/g (term1 is what you search for, term2 is what to replace it with)
  • Try the vimtutor program
  • Try to find the program traceroute using find (hint, you can limit your search to /usr )
  • create a .vimrc config file, put in 3 or more options. 5pts
Resources
Text Editor Help
rm help
find help