Vi Editor Exercise 1



  • In this exercise /etc/passwd is used, as it exists in every UNIX system.
    However it is not advised to use “vi” for user management!
  1. Copy the file /etc/passwd to your HOME-directory.
    Name your copy mypasswd
    Hint: your HOME-directory is the base directory for you as a user.

vi mypasswd


  • After you've inserted text, immediately return to Command Mode
  • Use the vi-option :set showmode
  1. Above the first line of this new file, add the line: This is just a test file!
    Hint: O (capital o)
  2. Add a new user to your test file.
    Hint: yyp
  3. See to it that the last line becomes the last line but one.
    Hint: ddp
  4. For the last 5 user accounts add the comment: UNIX user
    Hint: The comment field is the 5th field in the passwd file.
    Hint: Use the vi repeat command to make things painless.
  5. Make each line start with one TAB.
    Hint: Regular Expression characters ^ $
    Hint: :1,$s/ / /
  6. Try to undo your last change.
    Hint: u
  7. Use vi to copy all administrative users to a file called passwd.adm
    Hint: Administrative users are users like “root” and “lp”.
    This example shows how to copy lines to another file:
    :e passwd.adm
  8. Quit vi.
    Check if you have a file named .exrc in your HOME-directory. Make a backup copy of your existing .exrc
    Create the file $HOME/.exrc containing the following two lines:
    :set showmode
    :set list
  9. Use vi to reopen your test file and check which vi-options are available.
    Hint: :set all
  10. In your test file, pick one of the user accounts and use <space> to add a blank at the end of the login shell field.
    Is this blank visible?
    Which vi-option will make it visible?
    What do you think? Would it stll be possible to login with a blank after the shell in the real /etc/passwd?
    Remember this option! It's an invaluable option in debugging a non functioning config file!


Copyright (C) 2011 Integrated Services;
Author: Ing.J.M.Waldorp
vi-exercise1 20030514, 20110417

linux/vi/vi-exercise1.txt · Laatst gewijzigd: 2018/12/30 17:17 (Externe bewerking)