Tagterminal

Linux Shell Prompt Customized

Yes, I know it is not the most exciting thing in the world, but the simplest things are often the most meaningful, and for those of us who grew up before windows, or for those n00bs who are brave enough to dare travel the land of the command line, here’s a tip for you.  (That was all in one sentence… and it felt good)

You can customize your prompt in order to make it more effective.  My default prompt was about half a line long and didn’t really contain much useful information to me, so I changed it, including added a little color. Me? I like to see the time and my current directory, so that’s what I added using the instructions here, and even fancier color management instructions here. Simply put, I edited my .bashrc file’s prompt entry to the following. If you haven’t done this kind of edit before, first make a backup copy file.

PS1="\e[0;35m[\t]\e[m\w$ "

*UPDATE*

Ok, the above line looks pretty, but the text wrapping gets funked up. You have to put escaped opening and closing square brackets around the color code chunks.  The following revised line works great.

PS1="\[\e[0;35m\][\t]\[\e[m\]\w$ "

And here’s the before and after.

Ahhh…   almost zen.

Detach Process from Terminal Window

Running Ubuntu Linux and am starting an application process from my terminal window. The problem is, that window is then basically locked, not allowing me to execute more commands while the spawned application is running. To fix this, I found this command, where I basically add a & to the end of the line.
i.e.

~/tools/shell/mycommand &

This allows me to execute the command and gives me back access to the command prompt to execute more commands.

So the next issue I have is, if I close that terminal window, all processes that were spawned from that window are instantly killed. No warnings, pleases or thank-yous. That’s scary for those of us that don’t save often. Ah, but there are more solutions. After executing the command, as shown above, simple execute the following command, and it will separate spawned processes from that terminal window.

disown

Or, simpler yet, why not just kick the application off from in an independent process, right from the beginning, with this util-linux command.

setsid ~/tools/shell/mycommand

© 2024 Jer's Life

Theme by Anders NorenUp ↑