Monday, February 18, 2008

Quick tutorial on using vi

Open your favorite text file in vi:

% vi myfile.txt

Navigate to the text you wish to change using hte h, j, k, and l keys

j goes down
k goes up
h goes left
l goes right

Don't gets super intuitive after a while!

To jump to the last line of the file, type G

To jump to the first line of the file, type 1G

To insert some text starting at your cursor, type i, then type your text. Press Escape when you're done with your insert.

To delete the character under the cursor, type x

To undo what you last did, type u

To save your file, type :w

To save your file and quit, type either :wq or ZZ

To save without quitting, type :q!

To overwrite a file, even though it's listed as read-only, type :w!
The ! means you really, really mean it!!

To delete the rest of a word from where your cursor is, type dw

To change the rest of the word from where your cursor is, type cw. Press Escape when you're done with your insert.

To delete from where your cursor is to the end of the line, type d$

To change the text from your cursor to the end of the line, type c$. Press Escape when you're done with your insert.

To repeat your last command, type .

To search for a string in the file, type /, then type your string. Example: /Target
You can use ^string to find a string only at the beginning of the line, and string$ to find a string only at the end of the line.
To repeat your search, type n


To delete from wherever you are, all the way to the next occurance of a string, type d/

To change the text from your cursor to the next occurance of a string, type c/

Global search and replace.

Type %s/string/somethingelse/g to find all occurrences of "string" and to change it to "somethingelse"

The /g on the end makes it do it to the whole file. If you leave that off, it will just do it to the current line.

You can also add multipliers to your commands.

To delete from your cursor 5 characters, you don't need to type xxxxx. Just type 5x, and it will do the x 5 times.

Same works for changing/deleting words. 4dw deletes 4 words starting at the word you're on.

Saturday, February 16, 2008

Microsoft’s User State Migration Tool

(This is not a Unix trick)

USMT is the User State Migration Tool from Microsoft. It allows you to move whole user profiles from one system to another, copy them from one user account to another user account, or move someone on or off a domain. It's everything I've always wanted in a small-scale user profile manager for Windows. However, USMT is very hard to figure out, and it does not support newer versions of Firefox by default.

I've written some batch files to handle the actual command line options for the purposes of copying a domain user's settings from one PC to another, and added an additional configuration XML file to handle Firefox 2.x settings.

First, install USMT 3 on a computer. Any computer will do, it doesn't need to be the one you are ultimately using USMT on -- you just need the extracted files.

USMT can be downloaded from here.

The default install will put the files in C:\Program Files\USMT301. Then copy the USMT301 folder onto a USB drive. The whole thing.

Put this custom.xml file into the USMT301 folder on your USB drive, and put the these two .bat files into the root of your USB drive: restore-user.bat save-user.bat (rename the files from .bat.txt to .bat).

Modify the 2 .bat files, and replace the two "YOURDOMAIN"'s in each file with whatever your domain name is.

What you wind up with is a user migration USB drive. For large user profiles, you'll need a large drive. You could specify a network location in the batch files if you like, but in my environment it would be unnecessarily complex to also connect to the network drive while migrating an account (from a possibly dead/dying machine), and we don't necessarily want to be copying large files over the network if we don't have to. Some of my users do video and audio recording, so the profiles can get huge.

To use your new user migration USB drive, log in as Administrator on the computer you want to move the user off of, and open the USB drive. Run the save-user.bat file, and type in the user's name. Wait until it is done.

Then take the USB drive over to the new machine, log in as Administrator, open up the USB drive, and run the restore-user.bat file, and type in the user's name you want to import the profile into.

That is it!!

It should restore all the things that USMT is supposed to restore, and it will also do versions of Firefox newer than 1.8.

I've tested it with settings for Outlook, IE, Firefox, My Documents files, Desktop files, desktop pattern, and the Windows theme.