Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How do I make the shell prompt shorter in Linux?


  • Please log in to reply
10 replies to this topic

#1 Commodore64

Commodore64

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:29 PM

Posted 27 August 2017 - 01:13 PM

At present, my shell prompt contains my first and last name twice, my computer's Model #, and the $ prompt. How can I make the prompt shorter, ideally just the $ prompt? I couldn't find it in Linux for Dummies 9th Edition.

 

C64

 



BC AdBot (Login to Remove)

 


#2 MadmanRB

MadmanRB

    Spoon!!!!


  • Members
  • 2,616 posts
  • ONLINE
  •  
  • Gender:Male
  • Location:No time for that when there is evil afoot!
  • Local time:09:29 PM

Posted 27 August 2017 - 09:38 PM

https://www.cyberciti.biz/faq/ubuntu-change-hostname-command/

 

just replace the vi commands with your native text editor.


You know you want me baby!

Proud Linux user and dual booter.

Proud Vivaldi user.

 

ljxaqg-6.png


#3 rufwoof

rufwoof

  • Members
  • 94 posts
  • OFFLINE
  •  
  • Local time:02:29 AM

Posted 28 August 2017 - 02:41 PM

In my ~/.bashrc I just added

 

PS1="$ "

 

(and in roots home folder .bashrc added PS1="# "

 

I added that after other code that sets PS1 to a more fancy prompt

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
PS1="$ "

I have a borderless, noscrollbar, no window decoration xterm open at bootup so its like the desktop background is also in part a terminal session

 

2017-08-28-204430_1280x800_scrot.png

 

 

Which can make the desktop more animated (such as running htop)

 

2017-08-28-204828_1280x800_scrot.png


Edited by rufwoof, 28 August 2017 - 02:49 PM.

Debian and OpenBSD multiboot's


#4 Commodore64

Commodore64
  • Topic Starter

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:29 PM

Posted 28 August 2017 - 06:14 PM

Hello Worf (I hope you don't mind the abbr.),

 

I was able to find the place in my .bashrc file where you put the PS1="$ " cmd, but I saw a little later on that the program assigns the PS1 variable a new value. In addition, I was able to find the root directory by going up 2 levels, but the computer wouldn't let me have access to it even though it is a directory with rwx access for all users, and I own the computer now.

 

That's an interesting looking desktop you have there. Do you manually move the icons so that they are all around the 3 borders?

 

C64



#5 DeimosChaos

DeimosChaos

  • BC Advisor
  • 1,418 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States, Delaware
  • Local time:09:29 PM

Posted 29 August 2017 - 08:54 AM

Once set in .bashrc it shouldn't revert back...

 

Can you clarify what you mean by "the program assigns the PS1 variable a new value" ? What are you doing when that happens?

 

Also, please post your .bashrc contents.


Edited by DeimosChaos, 29 August 2017 - 08:55 AM.

OS - Ubuntu 14.04/16.04 & Windows 10
Custom Desktop PC / Lenovo Y580 / Sager NP8258 / Dell XPS 13 (9350)
_____________________________________________________
Bachelor of Science in Computing Security from Drexel University
Security +


#6 rufwoof

rufwoof

  • Members
  • 94 posts
  • OFFLINE
  •  
  • Local time:02:29 AM

Posted 29 August 2017 - 10:52 AM

Hello Worf (I hope you don't mind the abbr.),

 

I was able to find the place in my .bashrc file where you put the PS1="$ " cmd, but I saw a little later on that the program assigns the PS1 variable a new value. In addition, I was able to find the root directory by going up 2 levels, but the computer wouldn't let me have access to it even though it is a directory with rwx access for all users, and I own the computer now.

 

That's an interesting looking desktop you have there. Do you manually move the icons so that they are all around the 3 borders?

 

C64

 

Yes. My basic system is xorg, jwm (windows manager) and pcmanfm (filemanager). I also use pcmanfm to manage the desktop icons (by running pcmanfm --desktop). The icons can be dragged/dropped around the screen as desired. I have gkrellm installed/running that provides the far right system status values, and I create a wallpaper that aligns to that so it looks like its contained within a frame. I leave enough space in the middle to start up a xterm session that has no windows decorations nor frame/border, so it blends in with the desktop.

 

When jwm is the windows manager that involves adding

<StartupCommand>pcmanfm --desktop</StartupCommand>
<StartupCommand>xterm -uc -geometry 80x20+5+90</StartupCommand>
 
<Group>
    <Name>xterm</Name>
    <Option>nolist</Option>
    <Option>noborder</Option>
    <Option>notitle</Option>
    <Option>sticky</Option>
</Group>

to ~/.jwmrc so that any time xterm is run its borderless/undecorated. For a regular terminal with borders/title ...etc I use lxterminal

 

I also install brightside as one of my default choices and set the bottom left corner as a hot corner, so whenever I move the mouse into that corner the desktop is shown (handy/quick way to get-to/launch icons when you're viewing a full screened window).

 

The terminal shown that way is handy for ncurses type programs, for instance I have a short code of a 's' character that launches sc ... a small/quick spreadsheet and 'e' is set to launch a ncurses editor (that by default opens a notes.txt file). OK for quick/simple spreadsheeting/text editing ... for more complicated spreadsheets/text I tend to use LibreOffice.

 

2017-08-29-165644_1280x800_scrot.png
 

Try moving that PS1="$ " down towards the end of .bashrc. For the root version you'll have to be root to change that which you might be able to get into using either sudo or su (assuming you know the password).

 

su

<enter the root password>

cd     ... which will cd to the root home folder/directory

... and then edit the .bashrc in a similar manner to above except changing it to PS1="# "


Edited by rufwoof, 29 August 2017 - 10:58 AM.

Debian and OpenBSD multiboot's


#7 Commodore64

Commodore64
  • Topic Starter

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:29 PM

Posted 29 August 2017 - 07:40 PM

Once set in .bashrc it shouldn't revert back...

 

Can you clarify what you mean by "the program assigns the PS1 variable a new value" ? What are you doing when that happens?

 

Also, please post your .bashrc contents.

 

Hello. i know that if the PS1 variable is set in .bashrc, it shouldn't revert back outside of the program, but what if it's set to a new value inside the program after being set to "$ "? I found the place in the program where PS1 is set to "$ ", but a few lines down, PS1 is set to a new value. My .bashrc contents are basically the same as anyone else's, so I see no point in posting it.

 

Cheers,

C64



#8 Commodore64

Commodore64
  • Topic Starter

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:29 PM

Posted 29 August 2017 - 07:54 PM

 

Worf said:

 

Try moving that PS1="$ " down towards the end of .bashrc. For the root version you'll have to be root to change that which you might be able to get into using either sudo or su (assuming you know the password).

 

su

<enter the root password>

cd     ... which will cd to the root home folder/directory

... and then edit the .bashrc in a similar manner to above except changing it to PS1="# "

 

Okay, Worf, I'll move the PS1="$ " toward the end of .bashrc. I'll do the same for the root .bashrc, except I'll change it to PS1="# ".

 

The reason that I couldn't find the root directory before was because I thought it was called root, but in reality the root directory is just /, which means root.

I'll let you know if I can make the changes to the .bashrc files.

 

Cheers,

C64


Edited by Commodore64, 29 August 2017 - 07:55 PM.


#9 mremski

mremski

  • Members
  • 492 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NH
  • Local time:09:29 PM

Posted 30 August 2017 - 02:25 AM

"/" is the root directory (or the root of the directory tree), but it is typically not the "home directory for the user called root".  The home directory for the user called root is typically "/root".  The sequence laid out in #6 of the su command (become superuser) followed by the command cd (without any arguments) will take you to the user's home directory.  That's what cd without any arguments does.  Example:  logged in as your username, enter the command cd /usr/local/lib  hit return.  Then enter the command pwd  you should be in the directory /usr/local/lib  Now enter the command cd hit return then enter pwd.  You'll be back in your user's home directory (likely /home/username, also referred to a ~username).

Enter the command "cat /etc/passwd | grep ^root"  and look at the next to last field.  That is the home directory for the root user.  That's a vertical bar (pipe) and a caret (shift-6).  The pipe is how you string Unix commands together (stdout of one command feeds stdin of the next) the caret anchors the grep to the beginning of the line.  So the sequence is "cat the file /etc/passwd, pipe it into a grep command and look for lines that start with the word root"

 

If you call a shell program (shell script) from a terminal window, it can change the prompt by setting and exporting PS1.  Any shell on the system (bash is typical, tcsh/csh is another) will run through config in /etc (maybe /etc/profile or some subdirectories) then runs through .bash_profile and .bashrc in the user's home directory.  .bashrc is typically the last one run, so putting your changes at the bottom pretty much guarantee you'll get what you want.    "man bash" for a bunch more info.


FreeBSD since 3.3, only time I touch Windows is to fix my wife's computer


#10 Commodore64

Commodore64
  • Topic Starter

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:29 PM

Posted 30 August 2017 - 08:59 AM

 

 

Worf said:

 

Try moving that PS1="$ " down towards the end of .bashrc. For the root version you'll have to be root to change that which you might be able to get into using either sudo or su (assuming you know the password).

 

su

<enter the root password>

cd     ... which will cd to the root home folder/directory

... and then edit the .bashrc in a similar manner to above except changing it to PS1="# "

 

Okay, Worf, I'll move the PS1="$ " toward the end of .bashrc. I'll do the same for the root .bashrc, except I'll change it to PS1="# ".

 

The reason that I couldn't find the root directory before was because I thought it was called root, but in reality the root directory is just /, which means root.

I'll let you know if I can make the changes to the .bashrc files.

 

Cheers,

C64

 

Hi Worf,

 

It worked! In my .bashrc file, just above the last paragraph, I added PS1="$ ". Then I went to the root directory, but it didn't have a .bashrc file, just a /etc/bash.bashrc file, which I thought was close enough since I'm running Linux Mint 18.0. I edited the bash.bashrc file, and just before the last paragraph, entered PS1="# " on its own line. After I robooted, I got a "$ " prompt no matter what directory I went to. I can understand why PS1="$ " would do that, but why did I have to add PS1="# " to the bash.bashrc file?

 

Since you helped me out, I would like to tell you something. My background picture is big billowy clouds in the bottom half of the picture, and clear skies above, which makes it look like you're flying over the clouds in an airplane. That happens to be my motto: "It's always sunny above the clouds."

My screensaver is called nematode, which in real life is a long thin worm. On my screensaver, starting from the middle of the screen, different curved lines with different colors expand outward, then contract, with the ends of the lines having small spheres on them. It's the best screensaver I ever had.

 

Thank you for your help with the command prompt. :-)

 

Cheers,

C64



#11 Commodore64

Commodore64
  • Topic Starter

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:29 PM

Posted 30 August 2017 - 09:05 AM

"/" is the root directory (or the root of the directory tree), but it is typically not the "home directory for the user called root".  The home directory for the user called root is typically "/root".  The sequence laid out in #6 of the su command (become superuser) followed by the command cd (without any arguments) will take you to the user's home directory.  That's what cd without any arguments does.  Example:  logged in as your username, enter the command cd /usr/local/lib  hit return.  Then enter the command pwd  you should be in the directory /usr/local/lib  Now enter the command cd hit return then enter pwd.  You'll be back in your user's home directory (likely /home/username, also referred to a ~username).

Enter the command "cat /etc/passwd | grep ^root"  and look at the next to last field.  That is the home directory for the root user.  That's a vertical bar (pipe) and a caret (shift-6).  The pipe is how you string Unix commands together (stdout of one command feeds stdin of the next) the caret anchors the grep to the beginning of the line.  So the sequence is "cat the file /etc/passwd, pipe it into a grep command and look for lines that start with the word root"

 

If you call a shell program (shell script) from a terminal window, it can change the prompt by setting and exporting PS1.  Any shell on the system (bash is typical, tcsh/csh is another) will run through config in /etc (maybe /etc/profile or some subdirectories) then runs through .bash_profile and .bashrc in the user's home directory.  .bashrc is typically the last one run, so putting your changes at the bottom pretty much guarantee you'll get what you want.    "man bash" for a bunch more info.

Mrem, thanks a lot for the info. I'll have to read more of my LInux for Dummies Edition 9.

 

Cheers,

C64






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users