change vim as default editor

 add the following to your shell configuration (probably `~/.bashrc`):

    export VISUAL=vim
    export EDITOR="$VISUAL"


sudo update-alternatives --config editor


change interface name in Ubuntu

To rename interface eth0 to wan0, edit /etc/udev/rules.d/70-persistent-net.rules file and change

NAME="eth0" to NAME="wan0"


# PCI device 0x11ab:0x4363 (sky2)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:00:00:00:00:00",ATTR{dev_id}=="0x0", ATTR{type}=="1",
KERNEL=="eth*", NAME="wan0"


sed in MacOS

1, use G command to add a new line

2, use parameter in substitution command

dig +short

sudo cp /etc/pf.conf /etc/pf.conf_bak`date +%Y%m%d%H%M%S`

output_cmd="pass out proto tcp from any to ${1} port ${2}"

sudo sed -i '' -e '${G;}' /etc/pf.conf

sudo sed -i '' -e "$ s/$/$output_cmd/" /etc/pf.conf

sudo pfctl -evf /etc/pf.conf