8个实用而有趣Bash命令提示行
很多人都对过命令行提示的重要性不屑一顾,甚至是一点都不关心。但是我却一点都不这么认为,一个好的命令行提示可以改变你使用命令的方式。为此,我在internet上找到一些非常实用,优秀,并有趣的bash的命令行提示。下面我将我最喜欢使用的一些命令行提示罗列如下。
注意 - 要使用下面这些提示,你可以拷贝粘贴这些以”PS1″打头的内容到你的终端上,为了使你的改变永久生效,还要将这些内容粘贴到你使用用户的~/.bashrc文件中去。
1. 在成功执行的命令上增加一个笑脸符号
这个命令提示行可能是这个命令行提示列表中最有趣的一个,但是它也依然有使用的价值。这个提示的想法是基于当你命令被成功执行,你将会得到一个笑脸作为你的命令行提示,一旦的命令执行失败,命令行提示将会换成一个哭脸。
例子:
代码:
PS1=”\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\`[\u@\h:\w]\\$ “
2.更改失败命令的颜色
下面这个命令行提示是我最喜欢的命令行之一。和上一个相似,这个命令行提示的颜色会在你最后一个命令运行失败后改变,而且这个命令行长路径会缩短输入命令的空间,这个命令提示还包含了bash 每个历史命令的命令号,以方便重新提取运行。
例子:
代码:
PS1=”\[\033[0;33m\][\!]\`if [[ \$? = "0" ]]; then echo “\\[\\033[32m\\]“; else echo “\\[\\033[31m\\]“; fi\`[\u.\h: \`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo “\\W”; else echo “\\w”; fi\`]\$\[\033[0m\] “; echo -ne “\033]0;`hostname -s`:`pwd`\007″‘
3. 多行提示
如果你是喜欢命令行提示中包含完整信息的那一类人,那么下边就有一个适合于你的命令行提示。这个命令行提示信息中包含日期/时间,全路径,用户,主机,活动终端,甚至包含文件数和占用空间等。
例子:
代码:
PROMPT_COMMAND=’PS1=”\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e ’s:/dev/::’): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ’s: ::g’) files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ’s/total //’)b\[\033[0m\] -> \[\033[0m\]“‘
4. 多颜色提示
这个命令行提示除了使用了不同颜色来区别不同信息外,它并没有很特别的地方。就像你看到的那样,它提供了时间,用户名,主机名,当前目录。相当少的信息,但是非常地实用。
例子:
代码:
PS1=”\[\033[35m\]\t\[\033[m\]-\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ “
5.显示完整路径
这是一个良好,简洁,最小的2行提示(加上顶上的空行)。在第一行你能得到一个全路径信息,在第二行是一个用户名。如果你对每个命令提示行的空行不爽的话,你只要移走第一个\n就OK了
例子:
代码:
PS1=”[\[\033[32m\]\w]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;33m\]-> \[\033[0m\]“
6. 显示后台运行任务数
这是另外的一个两行提示,但是这个两行提示具有更多的之前我们没有的信息。第一行是显示通常的user@host和全路径等信息。在第二行我们可以得到命令执行历史序号和一个后台运行任务个数信息。
例子:
代码:
PS1=’\[\e[1;32m\]\u@\H:\[\e[m\] \[\e[1;37m\]\w\[\e[m\]\n\[\e[1;33m\]hist:\! \[\e[0;33m\] \[\e[1;31m\]jobs:\j \$\[\e[m\] ‘
7. 显示路径信息
这是一个非常眩的设计。我们可以从这个命令行提示信息的第一行中获取到用户/主机,运行任务数,和时间日期等信息。在第二行我们可以得到当前目录的文件数和他们占用的磁盘空间。
例子:
代码:
PS1=”\n\[\e[30;1m\]\[\016\]l\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n\[\016\]m\[\017\]-(\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ’s: ::g’) files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ’s/total //’)b\[\e[30;1m\])–> \[\e[0m\]“
8. My Prompt
最后这个命令提示行是我个人最喜欢的使用的命令提示行。它是#7的一个修改,这个命令提示行只包含我最希望知道的信息,因此节省了它的占用空间。我偏爱两行风格,因为这样不仅可以让我看到全路径信息,而且不影响我命令输入的可视空间。
例子:
代码:
PS1=”\n\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n(\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]“
如果你愿意共享你的命令提示行,请在将这些命令提示代码加在下面的评论中。
PS1=”\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed
-e ’s:/dev/::’): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed ’s: ::g’) files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed ’s/total //’)b\[\033[0m\] -> \[\033[0m\]”
Aug 11, 2010 06:13:48 PM
\[\016\]l\[\017\]
\[\016\]m\[\017\]
第七种里面的这两个是什么意思? 016和017看上去像是插入了ASCII码的16和17,但是这两个都是控制符....中间的l和m分别表示什么呢?
Aug 12, 2010 09:38:36 PM
看看这里吧,说明比较详细,个性
http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
Aug 13, 2010 05:38:14 PM
这篇不给力,并没有解释我的疑问.我没有找到m,只看到一个\l,并且不清楚是否就是第七种方式里的那个l
Aug 13, 2010 11:41:53 PM
好吧,我告诉你,我也不知道,我表示很无奈
Dec 25, 2010 04:23:17 AM
那个 m 是和 \e 以及中间的数字一起的,是 ANSI 控制码,与 bash 无关。目前我收集的资料只有这个 http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
Sep 28, 2022 01:43:48 PM
The English language is very essential for every people to survive anywhere in this World. Learning the English language may not be done in a short period of time, it should begin from a foundation of Education to make students understand and learn the language without any difficulties.That’s the way there are a huge number of English Medium Schools are teaching English as the First language to their students and those Hindi Medium and Urdu Medium students have chosen English as their Second or Third Langauge. NCERT English Question Paper Class 2 Those 2nd Standard students can download the NCERT English Sample Paper 2023 Class 2 designed based on the revised Syllabus and Curriculum.
May 23, 2023 01:28:29 AM
Wow, amazing weblog structure! How long have you been running a blog for? you made running a blog look easy. The whole look of your site is magnificent, neatly as the content material! Buy BSC Physician Assistant in India
May 25, 2023 06:15:43 PM
Hello! I just now would choose to supply a enormous thumbs up with the great information you could have here within this post. I will be coming back to your blog site for additional soon. house valuation
======================
The next time I just read a weblog, I really hope which it doesnt disappoint me up to this one. Get real, Yes, it was my choice to read, but I personally thought youd have something interesting to convey. All I hear can be a handful of whining about something you could fix in the event you werent too busy trying to find attention. medical centre Sydney
===========================
Thanks a lot for giving everyone an extraordinarily memorable chance to read in detail from this site. It is often so brilliant and packed with a lot of fun for me and my office acquaintances to search your site nearly thrice in a week to read through the latest items you will have. And definitely, I’m certainly astounded considering the exceptional ideas you serve. Certain two points in this post are really the most beneficial we’ve ever had. property styling
============================
Excellent blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as fast as yours lol retirement villages
=============================
Sweet site, super style and design , really clean and use friendly . patient management system
==============================
Thanks for this excellent article. One other thing is that a lot of digital cameras come equipped with the zoom lens that enables more or less of your scene to get included by means of ‘zooming’ in and out. All these changes in concentration length are usually reflected while in the viewfinder and on significant display screen right at the back of the specific camera. mortgage brokers in Australia
Jun 02, 2023 03:02:31 PM
articulo agregado a favoritos, lo imprimiré cuando llegue a la oficina. noticias financieras
======================
When I came over to this post I can only look at part of it, is this my net browser or the internet website? Should I reboot? moteros en la red
============================
I enjoy your composing design, do carry on creating! I will be back! CLASES DE BACHATA EN BARCELONA
Jun 12, 2023 11:37:08 PM
Just admiring your work and wondering how you managed this blog so well. It’s so remarkable that I can't afford to not go through this valuable information whenever I surf the internet! https://emprendeconhuevitos.com/
==================
If more people that write articles really concerned themselves with writing great content like you, more readers would be interested in their writings. Thank you for caring about your content. dragon ball game for android
Jun 22, 2023 09:32:09 PM
It is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait reading. I am impressed with your work and skill. Thanks. la pela pill
===========================
An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheers drop the info
Jun 26, 2023 02:09:27 PM
Helpful info. Lucky me I discovered your web site by chance, and I am surprised why this twist of fate didn’t happened in advance! I bookmarked it. 3ds roms
Jun 29, 2023 11:13:23 PM
Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. Football clubs for kids orpington
Jul 01, 2023 03:20:12 PM
Wow i can say that this is another great article as expected of this blog.Bookmarked this site.. desarrollo de software
======================
I would like to say that this blog really convinced me to do it! Thanks, very good post. Contrata perfiles senior
Jul 07, 2023 01:57:35 AM
I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well! Horario de misas en Bilbao
================================
This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! Las Poderosas Teatro: textos informativos que educan y entretienen a la vez
Jul 15, 2023 09:54:29 PM
Очень хорошо написана статья. Он будет поддерживать всех, кто его использует, включая меня. Продолжайте делать то, что вы делаете - не могу дождаться, чтобы прочитать больше сообщений. https://www.interactivemedia.az/xidmetlerimiz/sosial-media-marketinq/
Jul 20, 2023 11:21:39 PM
Generally I do not read article on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, quite nice article. cracked game pc
Aug 01, 2023 10:58:18 PM
I was also reading a topic like this one from another site. slot online
=================
Have you already setup a fan page on Facebook ?~’-”; spinix เว็บตรง
==================
You can increase your blog visitors by having a fan page on facebook. easyslot
===================
I am curious to find out what blog platform you have been utilizing? I’m having some minor security problems with my latest website and I would like to find something more risk-free. Do you have any solutions? slot easy
Aug 03, 2023 12:08:45 AM
Улучшенная разработка веб-сайтов и более удобный веб-дизайн ведут к большему удобству для пользователя. Лучшее содержание сайта означает более длительные разговоры с потенциальными клиентами. Ход и продолжительность разговора отражают доверие и уверенность клиента в вас. Все это делает ваш сайт более полезным, более профессиональным, короче говоря, лучшим сайтом в Интернете. логотип
Aug 04, 2023 06:11:01 PM
Spot lets start on this write-up, I must say i think this fabulous website needs far more consideration. I’ll probably be once more to learn far more, thank you that information. she hits different
Aug 25, 2023 01:48:45 AM
An intriguing discussion will probably be worth comment. I do believe that you simply write more on this topic, may possibly not be described as a taboo subject but usually consumers are there are not enough to talk on such topics. To the next. Cheers Descargar videos de Tiktok
Sep 02, 2023 02:48:19 PM
Bihar Board 2nd Question Paper 2024 Available From its our website in Hindi and English Medium Pdf Format. SCERT Bihar Board Upload Examination Department usually Question Bank in Every year Month of October, Bihar Board Important Question Paper 2024 help the Students to get an idea about the Annual Exam 2020. Bihar Model Test Paper 2024 is Provided by the State Council of Educational Research SCERT Bihar 2nd Class Model Paper 2024 and Training,Bihar Only,Bihar Board Model Paper 2024 have been Upload to Reveal the Exam Pattern to be Followed in SCERT Bihar Class Final Exam 2024, Bihar Class Latest Details along with Links to Download SCERT Bihar Question Paper 2024.
Sep 11, 2023 11:28:19 PM
“Thanks so much for this! I have not been this moved by a blog for a long time!” counterfeit money
Sep 13, 2023 10:53:34 AM
Board of Secondary Education Sikkim Adopt By has NCERT Textbooks at the High School Standard in Prepare by Senior experts. Sikkim Board once Publishes the Sikkim 7th Standard Textbooks 2024 Other Study Sikkim 7th Class Books 2024 materials on the official web site, we will update the Information on this page. Sikkim Board Assam e-Books 2024 Latest Version to be Upload Every Year in Online Mode. Textbooks are Very Important to Students on the Preparations of the Monthly and Final Examination.Sikkim Secondary Education Board Follows NCERT Curriculum These Textbooks are Updated as per the Syllabus Prescribed by Sikkim Board.
Sep 13, 2023 09:33:04 PM
Great goods from you, man. Ive understand your stuff previous to and you are just extremely wonderful. I really like what youve acquired here, certainly like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it smart. I cant wait to read much more from you. This is really a tremendous site. slot jackpot hari ini
================================
This was novel. I wish I could read every post, but i have to go back to work now… But I’ll return. slot jackpot
Sep 29, 2023 11:40:25 PM
A film like this couldn’t possibly be done years ago, and technology coupled with an artistic team’s imagination and reference from Thor’s source material, made the big battle sequences interesting. mpo800
=======================
I really like your writing style, fantastic information, thanks for posting : D. mpo100
=======================
i am very picky about baby toys, so i always choose the best ones’ kumpulan slot infini88
========================
Simply wanna remark that you have a very decent internet site , I love the design it actually stands out. kumpulan situs ug
========================
Hi there, just became alert to your blog through Google, and found that it’s really informative. I am gonna watch out for brussels. I’ll appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers! kumpulan slot mpo
Oct 26, 2023 11:42:25 PM
Thanks a lot for sharing this with all of us you actually know what you are talking about! Bookmarked. Kindly also visit my web site =). We could have a link exchange agreement between us! ラブドール
Oct 31, 2023 01:43:32 AM
After study many of the blog articles in your web site now, i really as if your method of blogging. I bookmarked it to my bookmark website list and will also be checking back soon. Pls look at my internet site also and make me aware how you feel. Cambio/reparar teclado macbook en barcelona
Nov 04, 2023 06:28:05 PM We are a group of volunteers and starting a new scheme in our community. Your site offered us with valuable information to work on. You’ve done a formidable job and our whole community will be thankful to you. sex shop online
Nov 04, 2023 10:26:19 PM
Thanks a lot for your energy to have had these things together on this site. Robin and that i very much liked your knowledge through the articles about certain things. I know that you have several demands on your program so the fact that you actually took just as much time just like you did to guide people just like us by means of this article is definitely highly liked. Amazon
Nov 05, 2023 10:41:30 PM
Great web site. A lot of helpful info here. I am sending it to a few friends ans also sharing in delicious. And naturally, thank you to your effort! Pristina Hotels 2003-ral
Nov 19, 2023 01:30:34 AM
i am very picky about baby toys, so i always choose the best ones; Subzero refrigerator repairman
Nov 20, 2023 05:31:09 PM
Can I just say what a aid to find somebody who truly knows what theyre speaking about on the internet. You positively know the right way to bring an issue to light and make it important. More people have to read this and understand this facet of the story. I cant believe youre not more standard because you undoubtedly have the gift. RelojesVip
Nov 28, 2023 09:35:33 PM
You have some real insight into the things you write about. Be sure to keep writing. Filtro para tortugas
====================
Ta for giving the hyperlink but unhappily it looks incapable to pull up? Will any person possess a mirror or even different supply? Netflix brazil gift card
Nov 28, 2023 11:25:40 PM
Youre so cool! I dont suppose Ive learn anything like this before. So good to seek out any person with some unique ideas on this subject. realy thanks for starting this up. this website is something that’s needed on the net, someone with a bit of originality. useful job for bringing something new to the web! DESIGNING A SHELL AND TUBE HEAT EXCHANGER (STHE)
Dec 03, 2023 01:45:44 AM
I'm sure there is a downside to your web blog making use of Safari internet browser. DESIGNING OF PLATE AND FRAME HEAT EXCHANGERS MANUFACTURER
Dec 04, 2023 12:02:23 AM
Hello! I know this is kinda off topic but I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa? My website goes over a lot of the same topics as yours and I feel we could greatly benefit from each other. If you are interested feel free to send me an email. I look forward to hearing from you! Terrific blog by the way! violencia pareja
==================
I came across your blog site on the internet and check a couple of of your earlier posts. Still keep in the very great operate. I simply extra up your Feed to my personal Windows live messenger News Readers. Searching for forward to reading far more from you afterwards!?- medidas tablero de basquetbol
Dec 05, 2023 02:14:59 AM
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something enlightening to read? uses of shell and tube heat exchanger
====================
depending on fossil fuel is always a bad idea, we should always concentrate on renewable energy:: plumbing services
Dec 07, 2023 11:42:44 PM
Hello There. I found your blog the use of msn. This is an extremely smartly written article. I’ll be sure to bookmark it and return to read more of your useful info. Thanks for the post. I will definitely comeback. PFAS TREATMENT PLANT PFAS REMOVAL SYSTEM MANUFACTURER
==========================
Nice post. I understand something harder on various blogs everyday. It will always be stimulating to see content from other writers and practice a little something from their website. I’d want to use some together with the content on my weblog regardless of whether you don’t mind. Natually I’ll supply you with a link on your own internet blog. Thank you sharing. Bitcoin Revolution Test
Dec 13, 2023 11:07:41 PM
Nice site. On your blogs very interest and i will tell a friends. molde de la letra r
====================
This article gives the light in which we can observe the reality. This is very nice one and gives in-depth information. Thanks for this nice article. Hotel Fazenda SP
=====================
If you’re still on the fence: grab your favorite earphones, head down to a Best Buy and ask to plug them into a Zune then an iPod and see which one sounds better to you, and which interface makes you smile more. Then you’ll know which is right for you. Government Jobs updates
Dec 18, 2023 06:22:26 PM
I genuinely treasure your work , Great post. 攝影器材
=====================
Would love to perpetually get updated great blog ! . 腳架