The hosts game
Jan. 27th, 2006 07:30 pmWe've been playing a geeky game this week: come up with a way of listing the contents of
/etc/hosts when the obvious file manipulation tools on your system are missing or broken. The solutions included:
grep ^ /etc/hosts
sed "" /etc/hosts
gzip -c /etc/hosts | gzcat
diff /dev/null /etc/hosts
My own, favoured, solution involves doing away with external tools and using the existing login shell to do the heavy lifting:
while read X; do echo $X; done < /etc/hosts
It's a neat hack because it's entirely self contained and because you're almost guaranteed to have some form of Bourne shell available to you, no matter how shredded the rest of the system is. I mean, if you don't have sh you're not even going to be able to start single user and the whole exercise becomes even more academic than it already is...