Loading

Linux下使用hostname命令自动获取IP

通过hostname命令可以自动获取IP,然后可以在Linux环境shell命令行开头加上IP地址。

修改用户文件.bash_profile里PS1变量值:

IP=$( hostname -I | cut -d" " -f1 )
export PS1="[\u@\[\e[31m\]$IP\[\e[m\](\h) \W]\\$ "
posted @ 2022-10-31 15:05  刘跑跑  阅读(317)  评论(0编辑  收藏  举报