Debian changes hostname

View operating system version information

# cat /etc/issue
Debian GNU/Linux 11 \n \l
# lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye
# hostnamectl
   Static hostname: ecs
         Icon name: computer-vm
           Chassis: 
        Machine ID: 
           Boot ID: 
    Virtualization: kvm
  Operating System: Debian GNU/Linux 11 (bullseye)
            Kernel: Linux 5.10.0-9-cloud-amd64
      Architecture: x86-64

Set hostname

# hostnamectl set-hostname jp

View current hostname

# hostname
jp
# cat /etc/hostname
jp

Modify the format of the command line prompt

# echo $PS1
${
    
    debian_chroot:+($debian_chroot)}\u@\h:\w\$

Add to ~/.bashrc file

PS1='\[\e[31m\]\u@\h:\W\[\e[0m\]\$ '
用户名@主机名:当前工作目录的基本名称$
PS1=:这是一个环境变量,用于设置命令行提示符的值。
\[\e[31m\]:这是一个转义序列,用于设置命令行提示符的颜色为红色。\e[31m 表示红色。
\u:这是一个转义序列,用于显示当前的用户名。
@:这是一个普通字符,表示用户名和主机名之间的分隔符。
\h:这是一个转义序列,用于显示当前的主机名。
::这是一个普通字符,表示主机名和当前工作目录之间的分隔符。
\W:这是一个转义序列,用于显示当前工作目录的基本名称(不包含完整路径)。
\[\e[0m\]:这是一个转义序列,用于重置命令行提示符的颜色和样式,将其恢复为默认值。\e[0m 表示重置为默认值。
\$:这是一个普通字符,表示命令行提示符。如果当前用户是超级用户(root),则显示 #,否则显示 $。

Guess you like

Origin blog.csdn.net/u010953692/article/details/134328976