LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2010, 08:51 AM   #1
thelink123
Member
 
Registered: Aug 2008
Location: India, Kerala
Distribution: openSUSE 11
Posts: 46

Rep: Reputation: 15
Thumbs up 'cd' command increases size of shell propmt


Hi LQ,

When i change the directory using 'cd', the length of my shell prompt keeps on increasing. To make it more clear kindly see below

Code:
$> cd MyWorks
$ Myworks> cd Shell
$ MyWorks /Shell>
How can i fix the size of the shell promptt like even if i change the directory the length of shell prompt should remain unchanged.
 
Old 09-10-2010, 09:12 AM   #2
rcbrgs
Member
 
Registered: Aug 2010
Posts: 30

Rep: Reputation: 14
You may remove the part of the shell prompt related to your current directory.

I assume you're using bash. So your prompt is regulated by the PS1 variable. You can check your PS1 variable with the command:

echo $PS1

It should be similar to this:

$ ~/Desktop >echo $PS1
$ \w >

You can simplify your prompt to never show the working directory, by exporting the PS1 variable with a new value:

export PS1="\$>"

Now your prompt will always be "$>" no matter what.

If you want to have the working directory, but truncated to a specific number of letters, you'll have to find something more fancy. I suggest you start reading "man bash" on the section "PROMPTING", and post your findings here. (You can also read that to understand in more detail the instructions I wrote above).
 
Old 09-10-2010, 09:12 AM   #3
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7/10
Posts: 893

Rep: Reputation: 119Reputation: 119
How come you are putting > cd?

you should just do it like this

$cd MyWorks
$cd Shell
and so on.
 
Old 09-10-2010, 09:15 AM   #4
rcbrgs
Member
 
Registered: Aug 2010
Posts: 30

Rep: Reputation: 14
Sorry, I thought from your previous post that your prompt included a ">", but now I see you don't.

I am not typing the ">", I had it displayed on the end of the prompt.

Without this, the commands I wrote should be:

$ ~/Desktop echo $PS1
$ \w

export PS1="\$ "
 
Old 09-10-2010, 09:19 AM   #5
rcbrgs
Member
 
Registered: Aug 2010
Posts: 30

Rep: Reputation: 14
$ ~/Desktop echo $PS1
$ \w
$ ~/Desktop export PS1="\$ "
$ echo $PS1
$
$ cd
$ cd /var/log/
$

As you can see, the prompt is always the same size. To know here you are, you should use the "pwd" command:

$ pwd
/var/log
 
Old 09-10-2010, 09:52 AM   #6
thelink123
Member
 
Registered: Aug 2008
Location: India, Kerala
Distribution: openSUSE 11
Posts: 46

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by rcbrgs View Post
You may remove the part of the shell prompt related to your current directory.

I assume you're using bash. So your prompt is regulated by the PS1 variable. You can check your PS1 variable with the command:

echo $PS1

It should be similar to this:

$ ~/Desktop >echo $PS1
$ \w >

You can simplify your prompt to never show the working directory, by exporting the PS1 variable with a new value:

export PS1="\$>"

Now your prompt will always be "$>" no matter what.

If you want to have the working directory, but truncated to a specific number of letters, you'll have to find something more fancy. I suggest you start reading "man bash" on the section "PROMPTING", and post your findings here. (You can also read that to understand in more detail the instructions I wrote above).
Thanks for the quick reply
 
Old 09-10-2010, 10:08 AM   #7
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
@ thelink123

The changes to the PS1 variable is temporary. To make it permanent, you'll need to edit /etc/bashrc and look for the PS1 variable line. This change will affect everyone on the system when they open a terminal. But, if you're the only user on linux, it's no problem.

If you have others using linux, and you want the PS1 prompt to apply to you only and no one else, you'll need to edit or create a hidden file called .bashrc in your home directory and add the line you want. For example:

export PS1="$ "

I use this for my prompt, export PS1="% " in my bashrc file.
%

I saw this prompt from a unix or sun terminal

- Cheers

Last edited by dv502; 09-10-2010 at 10:36 AM.
 
1 members found this post helpful.
Old 09-11-2010, 07:48 AM   #8
thelink123
Member
 
Registered: Aug 2008
Location: India, Kerala
Distribution: openSUSE 11
Posts: 46

Original Poster
Rep: Reputation: 15
Thumbs up

@dv502

Thanks I found out the same solution you provided in net. I was just about to add that for this thread, when i saw your post.

Thanks,
thelink123
 
Old 09-11-2010, 09:57 AM   #9
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
You're Welcome...
 
  


Reply

Tags
bashrc, cd, ps1, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket Programming, killing threads increases memory size gauravparihar Programming 1 03-27-2009 05:25 AM
Opening,Editing MS Word document in writer increases size tuxtuxtux Linux - Desktop 3 12-29-2008 03:04 PM
Can I make 'cd' behave this way? exitsfunnel Linux - Software 4 08-30-2003 05:57 PM
Concern about 'Run from CD' distro's davee General 10 05-07-2003 05:49 PM
Login Propmt davegage Linux - General 2 02-08-2001 09:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration