prompt是指终端提示符(Shell提示符),是在linux操作系统中,提示进行命令输入的一种工作提示符。对于普通用户,Base shell默认的提示符是美元符号“$”;对于超级用户(root用户),Bash Shell默认的提示符是井号“#”;该符号表示Shell等待输入命令。
prompt是指终端提示符,是在linux操作系统中,提示进行命令输入的一种工作提示符。
当您激活终端模拟器或者在 Linux 控制台登录后,即可呈现出 Shell 提示符。命令提示符是进入Shell的门户,也是输入Shell命令的位置。
对于普通用户,Base shell 默认的提示符是美元符号$
;对于超级用户(root 用户),Bash Shell 默认的提示符是井号#
。该符号表示 Shell 等待输入命令。
不同的 Linux 发行版使用的提示符格式不同。例如在 CentOS 中,默认的提示符格式为:
[mozhiyan@localhost ~]$
这种格式包含了以下三个方面的信息:
启动 Shell 的用户名,也即 mozhiyan;
本地主机名称,也即 localhost;
当前目录,波浪号~是主目录的简写表示法。
Shell 通过PS1和PS2两个环境变量来控制提示符格式:
PS1 控制最外层命令行的提示符格式。
PS2 控制第二层命令行的提示符格式。
在 Shell 中初次输入命令,使用的是 PS1 指定的提示符格式;如果输入一个命令后还需要输入附加信息,Shell 就使用 PS2 指定的提示符格式。请看下面的例子:
[mozhiyan@localhost ~]$ echo "本站" 本站 [mozhiyan@localhost ~]$ echo "https://www.yisu.com/" https://www.yisu.com/ [mozhiyan@localhost ~]$ echo " > yan > chang > sheng > " yan chang sheng [mozhiyan@localhost ~]$
echo is a command for printing that outputs numbers, variables, strings, etc. In this example, we are using echo to print a string.。
字符串是一组由" "包围起来的字符序列,echo 将第一个"作为字符串的开端,将第二个"作为字符串的结尾。此处的字符串就可以看做 echo 命令的附加信息。
在这个例子中,前两次使用 echo 命令时,都在同一行中紧接着字符串输入了所有的附加信息。第三次使用 echo 时,将字符串分成多行,echo 遇到第一个"认为是不完整的附加信息,所以会继续等待用户输入,直到遇见第二个"。输入的附加信息就是第二层命令,所以使用>作为提示符。
要显示提示符的当前格式,可以使用 echo 输出 PS1 和 PS2:
[mozhiyan@localhost ~]$ echo $PS1 [\u@\h \W]\$ [mozhiyan@localhost ~]$ echo $PS2 > [mozhiyan@localhost ~]$
Shell 使用以\为前导的特殊字符来表示命令提示符中包含的要素,这使得 PS1 和 PS2 的格式看起来可能有点奇怪。下表展示了可以在 PS1 和 PS2 中使用的特殊字符。
字符 | 描述 |
---|---|
\a | 铃声字符 |
\d | 格式为“日 月 年”的日期 |
\e | ASCII转义字符 |
\h | 本地主机名 |
\H | 完全合格的限定域主机名 |
\j | shell当前管理的作业数 |
\1 | shell终端设备名的基本名称 |
\n | ASCII换行字符 |
\r | ASCII回车 |
\s | shell的名称 |
\t | 格式为“小时:分钟:秒”的24小时制的当前时间 |
\T | 格式为“小时:分钟:秒”的12小时制的当前时间 |
\@ | 格式为am/pm的12小时制的当前时间 |
\u | 当前用户的用户名 |
\v | bash shell的版本 |
\V | bash shell的发布级别 |
\w | 当前工作目录 |
\W | 当前工作目录的基本名称 |
\! | 该命令的bash shell历史数 |
\# | 该命令的命令数量 |
\$ | 如果是普通用户,则为美元符号$ ;如果超级用户(root 用户),则为井号# 。 |
\nnn | 对应于八进制值 nnn 的字符 |
\\ | 斜杠 |
\[ | 控制码序列的开头 |
\] | 控制码序列的结尾 |
所有特殊字符均以反斜杠\作为前缀以便与普通字符区分。您可以在命令提示符中使用以上任何特殊字符的组合。
我们可以通过修改 PS1 变量来修改提示符格式,例如:
[mozhiyan@localhost ~]$ PS1="[\t][\u]\$ " [17:27:34][mozhiyan]$
新的 Shell 提示符现在可以显示当前的时间和用户名。不过这个新定义的 PS1 变量只在当前 Shell 会话期间有效,再次启动 Shell 时将重新使用默认的提示符格式。
The above is the detailed content of What does prompt refer to in linux?. For more information, please follow other related articles on the PHP Chinese website!

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools
