- 浏览: 697471 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
yzs5273:
没什么用。都试过了
WIN7下CS不能全屏的解决方法 -
di1984HIT:
不错,学习了
读取本地计算机中的安装程序列表 -
ffedu:
[flash=200,200][url][img][list] ...
linux/unix中如何用find命令详解,非常详细的介绍,比man find强100倍(转) -
lintghi:
...
Log4j使用相对路径指定log文件及使用总结 -
nick.s.ni:
唉,Java中引用的包没有介绍啊,如果数据库用UTF-8的格式 ...
Oracle 中Java 对象与PL/SQL类型的映射及使用(转)
How to: Change / Setup bash custom prompt (PS1) [reposted]
- 博客分类:
- Environment
So how do you setup, change and pimp out Linux / UNIX shell prompt?
Most of us work with a shell prompt. By default most Linux distro displays hostname and current working directory. You can easily customize your prompt to display information important to you. You change look and feel by adding colors. In this small howto I will explain howto setup:
a] Howto customizing a bash shell to get a good looking prompt
b] Configure the appearance of the terminal.
c] Apply themes using bashish
d] Howto pimp out your shell prompt
Prompt is control via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variable. If set, the value is executed as a command prior to issuing each primary prompt.
- PS1 - The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$ .
- PS2 - The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
- PS3 - The value of this parameter is used as the prompt for the select command
- PS4 - The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +
How do I display current prompt setting?
Simply use echo command, enter:$ echo $PS1
Output:
\\u@\h \\W]\\$
How do I modify or change the prompt?
Modifying the prompt is easy task. Just assign a new value to PS1 and hit enter key:
My old prompt --> [vivek@105r2 ~]$PS1="touch me : "
Output: My new prompt
touch me :
So when executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:
- \a : an ASCII bell character (07)
- \d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
- \D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
- \e : an ASCII escape character (033)
- \h : the hostname up to the first '.'
- \H : the hostname
- \j : the number of jobs currently managed by the shell
- \l : the basename of the shell’s terminal device name
- \n : newline
- \r : carriage return
- \s : the name of the shell, the basename of $0 (the portion following the final slash)
- \t : the current time in 24-hour HH:MM:SS format
- \T : the current time in 12-hour HH:MM:SS format
- \@ : the current time in 12-hour am/pm format
- \A : the current time in 24-hour HH:MM format
- \u : the username of the current user
- \v : the version of bash (e.g., 2.00)
- \V : the release of bash, version + patch level (e.g., 2.00.0)
- \w : the current working directory, with $HOME abbreviated with a tilde
- \W : the basename of the current working directory, with $HOME abbreviated with a tilde
- \! : the history number of this command
- \# : the command number of this command
- \$ : if the effective UID is 0, a #, otherwise a $
- \nnn : the character corresponding to the octal number nnn
- \\ : a backslash
- \[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
- \] : end a sequence of non-printing characters
Let us try to set the prompt so that it can display today’d date and hostname:PS1="\d \h $ "
Output:
Sat Jun 02 server $
Now setup prompt to display date/time, hostname and current directory:$ PS1="[\d \t \u@\h:\w ] $ "
Output:
[Sat Jun 02 14:24:12 vivek@server:~ ] $
How do I add colors to my prompt?
You can change the color of your shell prompt to impress your friend or to make your own life quite easy while working at command prompt.
Putting it all together
Let us say when you login as root/superuser, you want to get visual confirmation using red color prompt. To distinguish between superuser and normal user you use last character in the prompt, if it changes from $ to #, you have superuser privileges. So let us set your prompt color to RED when you login as root, otherwise display normal prompt.
Open /etc/bashrc (Redhat and friends) / or /etc/bash.bashrc (Debian/Ubuntu) or /etc/bash.bashrc.local (Suse and others) file and append following code:# vi /etc/bashrc
or$ sudo gedit /etc/bashrc
Append the code as follows
# If id command returns zero, you’ve root access. if [ $(id -u) -eq 0 ]; then # you are root, set red colour prompt PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]" else # normal PS1="[\\u@\\h:\\w] $" fi
Close and save the file.
My firepower prompt
Check this out:
(click to enlarge)
You can also create complex themes for your bash shell using bashish. Bashish is a theme enviroment for text terminals. It can change colors, font, transparency and background image on a per-application basis. Additionally Bashish supports prompt changing on common shells such as bash, zsh and tcsh. Install bashish using rpm or apt-get command:# rpm -ivh bashish*
OR# dpkg -i bashish*
Now start bashish for installing user configuration files:$ bashish
Next you must restart your shell by typing the following command:$ exec bash
To configure the Bashish theme engine, run$ bashishtheme
basish in action (screenshots from official site):
Finally, you can always use aterm or other terminal program such as rxvt. It supports nice visual effect , like transparency, tinting and much more by visiting profile menu. Select your terminal > click on Edit menu bar > Profiles > Select Profile > Click on Edit button > Select Effects tab > Select transparent background > Close
发表评论
-
Do POST with CURL
2016-01-18 16:58 0th fields: curl --data " ... -
DOS Command to remove shortcut arrow and add open command window here
2015-07-30 14:56 539@echo off echo. echo Removin ... -
How to Enable “Open Command Window Here” Option in Context Menu in Windows Vista
2015-07-29 19:58 933In Windows Vista and later, if ... -
Shell script for stress testing
2014-10-23 00:05 789ParseInstance() { Files=`f ... -
Shell操作字符串
2014-08-19 09:42 652在做shell批处理程序时候,经常会涉及到字符串相关操作 ... -
Linux设置shell提示符的方法
2014-05-16 16:52 735转自: http://www.linuxsong.org/2 ... -
Win7 - Failed to set image as wallpaper
2014-04-29 12:02 885Problem: Right click on an im ... -
JBoss 6.0.0 Final 启动慢且占用大量内存的解决方法
2014-02-22 22:53 13531. Patch jboss.jar (Can be op ... -
Linux Used内存到底哪里去了
2014-02-22 15:31 870原创文章,转载请注明: 转载自系统技术非业余研究 本文 ... -
Killing process via shell script
2014-02-14 15:59 507#!/bin/sh #Check input parame ... -
Install Chocolatey when you access Internet via proxy
2014-01-24 16:43 1158Modify install.ps1 like bel ... -
Startup script for configuring a workstation
2014-01-24 16:29 799@echo off ping -n 100 127 ... -
Shell skills take away
2014-01-16 17:45 7961. Empty log files in batch ... -
Building a java classpath from a windows batch file (Reposted)
2014-01-06 16:10 873A great feature introduced wi ... -
Shell操作数组
2014-01-03 19:20 958#pids=(123 345 678)pids=$(ps -e ... -
shell参数传递有空格的问题
2013-12-27 19:34 5772$# 传给脚本的参数个数$0 脚本本身的名字$1 传递给该s ... -
Shell Usage Sample
2013-12-27 19:08 1266Sample 1: if [ $# -ne 1 ] t ... -
用shell判断一个字符串是不是全为数字 & 取字符串的第N个字符(转)
2013-12-27 18:57 1616(1)判断一个字符串是不是全为数字 01 ... -
基本正则表达式和扩展正则表达式的区别
2013-12-23 09:31 1485sed默认的匹配方式是基本正则表达式,用基本正则表达式匹配时. ... -
Delete file with name start with dash
2013-11-25 11:52 852Sample file name: -a 1. rm - ...
相关推荐
在Linux系统中,当尝试运行一个Shell脚本(如`t.sh`)并遇到错误“bash: ./t.sh: /bin/bash^M: 损坏的解释器: 没有那个文件或目录”时,这通常意味着脚本的开头行(也称为Shebang行)受到了不兼容的文本编辑器的影响...
以上所述是小编给大家介绍的解决-BASH: /HOME/JAVA/JDK1.8.0_221/BIN/JAVA: 权限不够问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持! ...
这已经下载好了,下载之后,通过 bash ./downloadbyfn.sh 1.1.0 -s 运行。 具体可以看https://blog.csdn.net/u013288190/article/details/112286162
到此这篇关于Linux bash:./xxx:无法执行二进制文件报错的文章就介绍到这了,更多相关Linux 无法执行二进制文件 内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!...
-bash: /usr/local/jdk/jdk1.8.0_181/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 安装完后 java -version 查看版本出现: 原因是:没有那个文件或目录,找了很久发现需要...
如果出现“-bash: /usr/bin/yum: No such file or directory”的错误提示,这意味着系统找不到`yum`命令的执行路径,这通常是由于以下原因: 1. **yum命令未安装**:最直接的原因是`yum`这个包本身没有被正确地安装...
主要介绍了bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory,需要的朋友可以参考下
```bash sudo apt update ``` - 对于CentOS/RHEL: ```bash sudo yum update ``` 2. 安装MySQL Server: - Ubuntu/Debian: ```bash sudo apt install mysql-server ``` - CentOS/RHEL: ```bash ...
在安装过程中,如果遇到 `bash:./vmware-install.pl :/usr/bin/perl:bad interpreter: No such file or directory.` 的错误,说明系统缺少 Perl 环境。此时,可以通过以下命令安装 Perl 支持组: ```bash sudo yum ...
Mac OS X设置面对新机器的设置(或在全新安装OS后需要重新安装等),这是常见... /bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh ) "brew tap buo/cask-upgrade
下载二进制文件: 二进制文件官方给出两种方式 curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0 已经为大家下载好了
你知道Homebrew吗?它是macOS和Linux上的一个绝佳的终端软件包管理程序。与Linux上的apt-get、yum等相同,它拥有丰富的功能,能实现“即输即装”。只需一行命令“brew install xxx”,它就会自动给你安装上了!...
讲述linux操作系统的基本命令,第一个命令ls命令的使用
```bash sudo yum update -y ``` ### 二、安装依赖 Redis需要`gcc`编译器和`wget`下载工具,如果没有安装,可以使用以下命令进行安装: ```bash sudo yum install epel-release -y sudo yum install gcc wget -y ``...
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs ``` 安装完成后,检查Node.js和npm的版本,确认它们都是最新稳定版: ```bash node -v npm -v ``` #### 1.2 ...