Quick VI question

This "SHOULD" be a simple question,
but looking through several books has turned up nothing,
so I turn once again to the experts!!

How do you vi a file so that you can see special characters.

I believe my /etc/passwd file is being corrupted during an upgrade process, however the files "look" the same. I need to
vi /etc/passwd to see if there are any special characters being
thrown in.

Thanks
Recon

Sorry, vi can't do that. It's a text editor only.

od, xd, cat -b, vis may be utilities on your system that can do this.

If you think /etc/passwd might get stepped on, save a copy! Any updates to any file always change the times in the inode. Look at the times to see if any changes occurred. Also use cmp on /etc/passwd and your copy. It will report any differences and works well with any binary values. Also you can use cksum to detect changes.

In command mode, go to the command prompt (the :slight_smile: and type
set list

This should show non-printable characters in vi.

Actually, with most versions of unix, ":set list" only affects white space. It causes tabs to show up as ^I and newlines to be marked with $.

The real problem is that some bytes could have values in the range of 128 to 255 and you may not have an 8 bit data path to your terminal. Depending on the stty settings, the MSB may be a parity bit rather than a data bit. Also not all terminals will display something for non-ascii characters. And a final problem is that, I think, vi balks at attempting to display nulls, although it will count them and display a count at startup time.

I stand corrected. Perderabo is absolutely correct. I didn't have a UNIX box handy when I answered, so no man pages. I faintly remembered set list showed some type of control characters.
Sorry.

Click here for a printable VI on-line reference.

BTW: Not sure, but perhaps you can use diff to compare the two files. I don't think (but not sure) you will get an exact match with diff if special or hidden chars are present.... perhaps someone could comment?

Also, you might consider playing round with stty and the flags for raw and cooked modes. I recall a few years ago using stty in raw mode to help find/print special chars.... not sure if we used vi or just cat to display.... somehow I recall playing with both stty and vi to find hidden chars in a file, but it has been many years ago....

stty man page here ...

Try emacs. It will display nulls as ^@

It will even let you delete it with Ctrl-d (Control and letter d) to delete 1 character.

I'm not an emacs user but it comes in handy sometimes.