- 浏览: 686127 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
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 508@echo off echo. echo Removin ... -
How to Enable “Open Command Window Here” Option in Context Menu in Windows Vista
2015-07-29 19:58 896In Windows Vista and later, if ... -
Shell script for stress testing
2014-10-23 00:05 748ParseInstance() { Files=`f ... -
Shell操作字符串
2014-08-19 09:42 619在做shell批处理程序时候,经常会涉及到字符串相关操作 ... -
Linux设置shell提示符的方法
2014-05-16 16:52 702转自: http://www.linuxsong.org/2 ... -
Win7 - Failed to set image as wallpaper
2014-04-29 12:02 855Problem: Right click on an im ... -
JBoss 6.0.0 Final 启动慢且占用大量内存的解决方法
2014-02-22 22:53 13031. Patch jboss.jar (Can be op ... -
Linux Used内存到底哪里去了
2014-02-22 15:31 829原创文章,转载请注明: 转载自系统技术非业余研究 本文 ... -
Killing process via shell script
2014-02-14 15:59 483#!/bin/sh #Check input parame ... -
Install Chocolatey when you access Internet via proxy
2014-01-24 16:43 1129Modify install.ps1 like bel ... -
Startup script for configuring a workstation
2014-01-24 16:29 761@echo off ping -n 100 127 ... -
Shell skills take away
2014-01-16 17:45 7601. Empty log files in batch ... -
Building a java classpath from a windows batch file (Reposted)
2014-01-06 16:10 842A great feature introduced wi ... -
Shell操作数组
2014-01-03 19:20 924#pids=(123 345 678)pids=$(ps -e ... -
shell参数传递有空格的问题
2013-12-27 19:34 5687$# 传给脚本的参数个数$0 脚本本身的名字$1 传递给该s ... -
Shell Usage Sample
2013-12-27 19:08 1233Sample 1: if [ $# -ne 1 ] t ... -
用shell判断一个字符串是不是全为数字 & 取字符串的第N个字符(转)
2013-12-27 18:57 1568(1)判断一个字符串是不是全为数字 01 ... -
基本正则表达式和扩展正则表达式的区别
2013-12-23 09:31 1406sed默认的匹配方式是基本正则表达式,用基本正则表达式匹配时. ... -
Delete file with name start with dash
2013-11-25 11:52 788Sample file name: -a 1. rm - ...
相关推荐
NULL 博文链接:https://appleses.iteye.com/blog/1936995
主要介绍了Shell脚本bash: ./t.sh:/bin/bash^M:损坏的解释器: 没有那个文件或目录,需要的朋友可以参考下
这已经下载好了,下载之后,通过 bash ./downloadbyfn.sh 1.1.0 -s 运行。 具体可以看https://blog.csdn.net/u013288190/article/details/112286162
到此这篇关于Linux bash:./xxx:无法执行二进制文件报错的文章就介绍到这了,更多相关Linux 无法执行二进制文件 内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!...
解决Centos6.7:-bash: ./DrClientLinux: /lib/ld-linux.so.2: bad ELF 的所有rpm包
以上所述是小编给大家介绍的解决-BASH: /HOME/JAVA/JDK1.8.0_221/BIN/JAVA: 权限不够问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持! ...
使用git Bash here闪退并生成mintty.exe.stackdump文件 cmd使用git 报错 fatal:open /dev/null or dup failed: No such file or directory 并弹出mitty.dump文件 使用方法见我的CSDN
-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 查看版本出现: 原因是:没有那个文件或目录,找了很久发现需要...
Cygwin的包管理工具setup.exe实在是难用的让人蛋碎。于是就有了这样一个apt-cyg,可以提供类似于 apt-get 的体验。 apt-cyg使用bash编写,所以连编译都省了。 安装apt-cyg wget ...
主要介绍了bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory,需要的朋友可以参考下
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 已经为大家下载好了
linux输入yum后提示: -bash: /usr/bin/yum: No such file or directory的解决方案 今天在安装程序时,发现有一个插件未安装,我就随手敲了一个命令,看都没看 yum remove yum 然后就杯具了… [root@localhost ~]#...
讲述linux操作系统的基本命令,第一个命令ls命令的使用
CentOS7安装VMware Tools 在安装VMware-tools出现bash:./vmware-install.pl :/usr/bin/perl:bad interpreter:No such file or directory.处理方式
Bash-Prompt-HOWTO.pdf