linux 登录模式的修改 -bash-3.2$ [user@localhost ~]#

本文介绍如何在Linux系统中定制命令行提示符(PS1)的显示样式,包括使用特殊符号显示用户、主机和路径信息,以及如何设置带有颜色的提示符。
Linux修改环境变量PS1(命令行提示符),可以使用vi编辑/etc/profile文件,在最后加上:export PS1="[\u@\h \W]\\$"即可,其中u显示当前用户账号,h显示当前主机名,W显示当前路径,$显示’$'符号

W 代替 w 就可以实现绝对路径到相对路径的转换



下面简单说说环境下默认的特殊符号所代表的意义:

d :代表日期,格式为weekday month date,例如:”Mon Aug 1″

H :完整的主机名称。例如:我的机器名称为:fc4.linux,则这个名称就是fc4.linux

h :仅取主机的第一个名字,如上例,则为fc4,.linux则被省略

t :显示时间为24小时格式,如:HH:MM:SS

T :显示时间为12小时格式

A :显示时间为24小时格式:HH:MM

u :当前用户的账号名称

v :BASH的版本信息

w :完整的工作目录名称。家目录会以 ~代替

W :利用basename取得工作目录名称,所以只会列出最后一个目录

# :下达的第几个命令

$ :提示字符,如果是root时,提示符为:# ,普通用户则为:$



但是这样设置之后显示的提示符是没有颜色的,如果希望加入颜色设置,可以这样:

PS1=”e[1;32mue[me[1;33m@e[me[1;35mhe[m:w$ "
此时,在终端中的显示应该是彩色的提示符了,其中的e[1;xxm和e[m就是改变终端字体颜色的部分,前者是修改颜色,后者是恢复到正常显示。但是 这时还会有问题,在提示符中输入第一行时,回车换行不正常,导致显示很混乱,因此,除了这个修改之外,还需要将全部非打印字符用专用的 bash 转义序列 "[" 和 "]” 括起来。这两个序列通知 bash,被括起来的字符不占用行 上的任何空间,这样就使自动换行能够继续正常工作。最终版本如下(可解决带颜色提示符的不换行问题):

PS1=”[e[1;32m]u[e[m][e[1;33m]@[e[m][e[1;35m]h[e[m]:w$ “

其中,颜色表示为:30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white。



如果需要改变目录在命令行下显示颜色:

1、将/etc/DIR_COLORS文件cp到~/下,并改名为.dir_colors。

2、编辑.dir_colors文件,找到“DIR 01;34 # directory”,将34改为36。


你可以找到文件的两行注释:
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
按照颜色对应的数字,你还可以把目录显示颜色改成其他的。
同样其他的显示效果(包括背景)也可以参照说明进行修改。
这样你就可以定制自己的linux下命令行方式下的个性化显示效果了。
[root@localhost ~]# # 完整配置流程 [root@localhost ~]# sudo mkdir -p /var/ftp/upload [root@localhost ~]# sudo chmod 775 /var/ftp/upload [root@localhost ~]# sudo semanage fcontext -a -t public_content_rw_t "/var/ftp/upload(/.*)?" [root@localhost ~]# sudo restorecon -Rv /var/ftp restorecon reset /var/ftp/upload context unconfined_u:object_r:public_content_t:s0->unconfined_u:object_r:public_content_rw_t:s0 [root@localhost ~]# sudo setsebool -P allow_ftpd_full_access=1 [root@localhost ~]# sudo systemctl restart vsftpd Failed to restart vsftpd.service: Unit not found. [root@localhost ~]# ^C [root@localhost ~]# # 检查目录上下文 [root@localhost ~]# ls -Zd /var/ftp # 应显示 public_content_rw_t drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 /var/ftp [root@localhost ~]# [root@localhost ~]# # 检查布尔值状态 [root@localhost ~]# getsebool -a | grep ftp ftpd_anon_write --> off ftpd_connect_all_unreserved --> off ftpd_connect_db --> off ftpd_full_access --> on ftpd_use_cifs --> off ftpd_use_fusefs --> off ftpd_use_nfs --> off ftpd_use_passive_mode --> off httpd_can_connect_ftp --> off httpd_enable_ftp_server --> off tftp_anon_write --> off tftp_home_dir --> off [root@localhost ~]# # 模拟文件上传测试 [root@localhost ~]# echo "test" | sudo tee /var/ftp/incoming/testfile.txt tee: /var/ftp/incoming/testfile.txt: 没有那个文件或目录 test [root@localhost ~]# curl -T localfile.txt ftp://localhost/incoming/ curl: Can&#39;t open &#39;localfile.txt&#39;! curl: try &#39;curl --help&#39; or &#39;curl --manual&#39; for more information [root@localhost ~]# # 检查服务是否安装 [root@localhost ~]# rpm -q vsftpd 未安装软件包 vsftpd [root@localhost ~]# [root@localhost ~]# # 检查服务单元是否存在 [root@localhost ~]# systemctl list-unit-files | grep vsftpd [root@localhost ~]# sudo yum install vsftpd -y 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 vsftpd.x86_64.0.3.0.2-29.el7_9 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================== Package 架构 版本 源 大小 ======================================================================================================================== 正在安装: vsftpd x86_64 3.0.2-29.el7_9 updates 173 k 事务概要 ======================================================================================================================== 安装 1 软件包 总下载量:173 k 安装大小:353 k Downloading packages: vsftpd-3.0.2-29.el7_9.x86_64.rpm | 173 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : vsftpd-3.0.2-29.el7_9.x86_64 1/1 warning: /etc/vsftpd/vsftpd.conf created as /etc/vsftpd/vsftpd.conf.rpmnew 验证中 : vsftpd-3.0.2-29.el7_9.x86_64 1/1 已安装: vsftpd.x86_64 0:3.0.2-29.el7_9 完毕! [root@localhost ~]# sudo vi /etc/vsftpd/vsftpd.conf [root@localhost ~]# # 设置FTP目录上下文 (以/var/ftp为例) [root@localhost ~]# sudo semanage fcontext -a -t public_content_rw_t "/var/ftp(/.*)?" libsemanage.dbase_llist_query: could not query record value [root@localhost ~]# sudo restorecon -Rv /var/ftp restorecon reset /var/ftp context system_u:object_r:public_content_t:s0->system_u:object_r:public_content_rw_t:s0 restorecon reset /var/ftp/pub context system_u:object_r:public_content_t:s0->system_u:object_r:public_content_rw_t:s0 [root@localhost ~]# [root@localhost ~]# # 启用关键布尔值 [root@localhost ~]# sudo setsebool -P allow_ftpd_full_access=1 [root@localhost ~]# sudo setsebool -P ftp_home_dir=1 Boolean ftp_home_dir is not defined [root@localhost ~]# # 重载服务配置 [root@localhost ~]# sudo systemctl daemon-reload [root@localhost ~]# [root@localhost ~]# # 启动服务 [root@localhost ~]# sudo systemctl start vsftpd Job for vsftpd.service failed because the control process exited with error code. See "systemctl status vsftpd.service" and "journalctl -xe" for details. [root@localhost ~]# [root@localhost ~]# # 检查服务状态 [root@localhost ~]# sudo systemctl status vsftpd ● vsftpd.service - Vsftpd ftp daemon Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since 六 2025-10-18 09:28:55 CST; 107ms ago Process: 5291 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=2) 10月 18 09:28:55 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon... 10月 18 09:28:55 localhost.localdomain vsftpd[5291]: 500 OOPS: bad bool value in config file for: anon_upload_enable 10月 18 09:28:55 localhost.localdomain systemd[1]: vsftpd.service: control process exited, code=exited status=2 10月 18 09:28:55 localhost.localdomain systemd[1]: Failed to start Vsftpd ftp daemon. 10月 18 09:28:55 localhost.localdomain systemd[1]: Unit vsftpd.service entered failed state. 10月 18 09:28:55 localhost.localdomain systemd[1]: vsftpd.service failed. [root@localhost ~]# # 测试本地用户上传 [root@localhost ~]# echo "test" > testfile.txt [root@localhost ~]# ftp -n localhost <<EOF > user <您的用户名> <密码> > put testfile.txt > quit > EOF bash: ftp: 未找到命令... [root@localhost ~]# [root@localhost ~]# # 检查SELinux日志 [root@localhost ~]# sudo ausearch -m avc -c vsftpd | audit2why <no matches> Nothing to do
10-19
[dragon@localhost ~]$ rpm -qa | grep qt5-qtbase # 查看当前版本 qt5-qtbase-postgresql-5.11.1-23.ky10.x86_64 qt5-qtbase-mysql-5.11.1-23.ky10.x86_64 qt5-qtbase-common-5.11.1-23.ky10.noarch qt5-qtbase-gui-5.11.1-23.ky10.x86_64 qt5-qtbase-5.11.1-23.ky10.x86_64 [dragon@localhost ~]$ strings /usr/lib64/libQt5Core.so.5 | grep "Qt_5\." # 检查符号版本 Qt_5.11.1_PRIVATE_API Qt_5.0 Qt_5.1 Qt_5.2 Qt_5.3 Qt_5.4 Qt_5.5 Qt_5.6 Qt_5.7 Qt_5.8 Qt_5.9 Qt_5.10 Qt_5.11 [dragon@localhost ~]$ sudo yum install -y https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm Last metadata expiration check: 0:18:08 ago on 2025年11月03日 星期一 19时0331秒. [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [MIRROR] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [FAILED] qt5-qtbase-5.15.3-1.el8.x86_64.rpm: Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) Status code: 404 for https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/q/qt5-qtbase-5.15.3-1.el8.x86_64.rpm (IP: 198.18.2.16) [dragon@localhost ~]$ sudo ldconfig [dragon@localhost ~]$ echo &#39;export PATH=$PATH:/usr/lib/virtualbox&#39; | sudo tee -a /etc/profile export PATH=$PATH:/usr/lib/virtualbox [dragon@localhost ~]$ source /etc/profile [dragon@localhost ~]$ sudo /sbin/vboxconfig # 查看详细错误 vboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Starting VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong. There were problems setting up VirtualBox. To re-start the set-up process, run /sbin/vboxconfig as root. If your system is using EFI Secure Boot you may need to sign the kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load them. Please see your Linux system&#39;s documentation for more information. [dragon@localhost ~]$ dmesg | grep vboxdrv # 检查内核日志 dmesg: 读取内核缓冲区失败: 不允许的操作 [dragon@localhost ~]$ sudo yum install -y kernel-devel-$(uname -r) gcc make Last metadata expiration check: 0:19:01 ago on 2025年11月03日 星期一 19时0331秒. Package kernel-devel-4.19.90-23.59.v2101.ky10.x86_64 is already installed. Package gcc-7.3.0-20190804.h30.p05.ky10.x86_64 is already installed. Package make-1:4.2.1-15.ky10.x86_64 is already installed. Dependencies resolved. Nothing to do. Complete! [dragon@localhost ~]$ # 生成密钥 sudo mokutil --import MOK.der # 导入密钥(需设置密码) [dragon@localhost ~]$ sudo openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=VirtualBox/" Generating a RSA private key ..............................+++++ ..........+++++ writing new private key to &#39;MOK.priv&#39; ----- [dragon@localhost ~]$ sudo mokutil --import MOK.der # 导入密钥(需设置密码)input password: input password again: [dragon@localhost ~]$ sudo rpm -ivh VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm 警告:VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 2980aecf: NOKEY 错误:依赖检测失败: libQt5Core.so.5(Qt_5.12)(64bit) 被 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 需要 libSDL-1.2.so.0()(64bit) 被 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 需要 libvpx.so.5()(64bit) 被 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 需要 [dragon@localhost ~]$ sudo VBoxManage extpack install Oracle_VM*.vbox-extpack --accept-license=56be48f923303c8cbabbgbbg WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (4.19.90-23.59.v2101.ky10.x86_64) or it failed to load. Please recompile the kernel module and install it by sudo /sbin/vboxconfig You will not be able to start VMs until this problem is fixed. VBoxManage: error: Failed to create the VirtualBox object! VBoxManage: error: Code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available) VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start. [dragon@localhost ~]$ sudo rpm -ivh VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm --nodeps 警告:VirtualBox-6.1-6.1.46_158378_el8-1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 2980aecf: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 软件包 VirtualBox-6.1-6.1.46_158378_el8-1.x86_64 已经安装 [dragon@localhost ~]$ sudo VBoxManage extpack install Oracle_VM*.vbox-extpack --accept-license=56be48f923303c8cbabbgbbg WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (4.19.90-23.59.v2101.ky10.x86_64) or it failed to load. Please recompile the kernel module and install it by sudo /sbin/vboxconfig You will not be able to start VMs until this problem is fixed. VBoxManage: error: Failed to create the VirtualBox object! VBoxManage: error: Code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available) VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start. [dragon@localhost ~]$ VBoxManage list extpacks | grep "Extension Packs" VBoxManage: error: Failed to create the VirtualBox object! VBoxManage: error: Code NS_ERROR_FACTORY_NOT_REGISTERED (0x80040154) - Class not registered (extended info not available) VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start.
最新发布
11-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值