/etc/hosts has tons of duplicate entries

I added a line to the /etc/hosts file per http://library.linode.com/getting-started/.

Later I checked back and there are hundreds if not thousands of duplicates of that line I added. Is this a problem? Have I done something wrong?

Note: I am newwb with a double double u, and I do fully understand what /etc/hosts does

4 Replies

did you use vim to edit the file?

my guess is you fat fingered by pressing numbers within command mode and accidentally duplicated a line while saving and exiting.

just delete them (in vim, dd deletes a line, 10dd deletes 10 lines) it won't happen again (unless you press numbers while in command mode again)

One way to remove duplicate lines:

uniq /etc/hosts > hosts.temp

Look at the hosts.temp file to make sure it's what you want. Edit if necessary (nano is a bit more user-friendly than vi). Then replace the hosts file with:

mv hosts.temp /etc/hosts

Another way to remove surplus lines.

Delete the hosts file with thousands of bogus lines.

Create a new hosts file with the 3-4 lines that you require.

thanks for the comprehensive reply. all it happy again

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct