Artificial intelligent assistant

How do I change a section of a host name permanently on multiple host names as a root user? I am doing a project for uni and an unsure how to proceed i have been given the task of changing hosts name from one thing to another on a unix box I am logged in to the box as root the host name is `garnet.bct.bolton.ac.uk garnet` I need to change `.bct` to `.amt` The new host name should be `garnet.amt.bolton.ac.uk garnet` I have multiple hostname in `cat /etc/hosts` and they all need changing from `bct` to `amt` I think I need to use `grep` but that is as far as I have gotten `cat /etc/hosts | grep bct`

Yo've not stated what your *nix is. But...

From what I can gather, you have two tasks there:

1. Change the hostname of the unix box
2. Change how that unix box resolves other systems on the network.



For the first, you need to edit the file `/etc/hostname` and change it.


nano /etc/hostname


For the second, you need to change all the instances of `bct` to `amt` in `/etc/hosts`. You can either do this with an interactive editor or you can script it with `sed`.

Interactively:


nano /etc/hosts


With `sed`:

First, run:


sed 's/\.bct\.bolton/\.amt\.bolton/g` /etc/hosts


and make sure that it looks ok. That simply shows you what it would change. To make the changes, add the `-i` option:


sed -i 's/\.bct\.bolton/\.amt\.bolton/g` /etc/hosts

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 62fdb04c1e6d0bf33c7a4da9f1c314b8