Skip to content

Instantly share code, notes, and snippets.

@ryanmaclean
Last active April 23, 2024 18:39
Show Gist options
  • Save ryanmaclean/107cb7b7105fd20d2e87 to your computer and use it in GitHub Desktop.
Save ryanmaclean/107cb7b7105fd20d2e87 to your computer and use it in GitHub Desktop.
Append or Replace /etc/hosts using Tee
#! /bin/bash
echo "127.0.0.1 localhost" | sudo tee --append /etc/hosts
echo "127.0.0.1" `ec2metadata --local-hostname` | sudo tee --append /etc/hosts
## Remove --append to overwrite the file
@SGmuwa
Copy link

SGmuwa commented Nov 27, 2023

sudo tee --append /etc/hosts <<< "127.0.0.1 localhost"
sudo tee --append /etc/hosts <<< "127.0.0.1 `ec2metadata --local-hostname`"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment