Ok, so i am trying to create an alias, that would allow me to set the current directory in the terminal, the base directory to be displayed in prompt. Let's assume the alias is named basedir

For instance:

andrepadez@theLookingGlass:~$ cd Shared  
andrepadez@theLookingGlass:~/Shared$ cd development/  
andrepadez@theLookingGlass:~/Shared/development$ cd nodejs/

right now, i would run that alias and i would get the following prompt:


from now, every time i change to a forward directory, i would get the prompts:

andrepadez@theLookingGlass:nodejs$cd project1
andrepadez@theLookingGlass:nodejs/project1$cd static
andrepadez@theLookingGlass:nodejs/project1/static$cd ..
andrepadez@theLookingGlass:nodejs/project1$ ...

(i really don't care what happens if i go back to folders behind my base directory)

Is there a way to create such a command?
I have found something close, but it always shows only the current directory:

alias basedir="export PS1='\u@\h:\W$ '"



In your home directory, there is a hidden file (starting with .) named .bashrc. This file is run whenever you login, and sets things like the prompt (environment variable PS1), and aliases. The PS1 variable is set in several places, depending upon the type of terminal you are running -- change them all, or just the one you are using. The existing PS1 setup has several codes which get expanded into things like the current working directory path (the \w). Edit the .bashrc file (you own it, so no sudo needed). Change the \w wherever the `PS1 being set to:


To set the alias BASE, you can add it to the section # some more ls aliases in the .bashrc file. Its value is just the value of the PWD variable, so

export BASE="$PWD"  

(The quotes would handle the oddities like spaces in directory names).

| improve this answer | |
  • I'm sorry, i am a n00b in linux bash. Can you please be more specific about the steps to be taken? thanks – André Alçada Padez Nov 23 '12 at 14:52
  • @AndréAlçadaPadez In case you didn't get this resolved already: can you be more specific about what you didn't understand or couldn't do? ubfan1's answer seems fairly complete to me. – isomorphismes Apr 27 '13 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.