My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Thursday, November 14, 2019

How to show full working directory in mac terminal on every command


Problem description:
You can obviously use a pwd command to see the present working directory. For eg:

prompt$ pwd
/Users/mfaiz/myDir

But sometimes you want to show the full directory path every time. Its a common ask for eg:
/Users/mfaiz/myDir$ pwd


Or, better still you want the directory path to be displayed on top before each command. All such issues can be handled using your bash profile file:


vi ~/.bash_profile


Solution: 
You can add this line -
export PS1='\u@\H:\w$'

or, if you like having a space between the $ and the command, then - 
export PS1='\u@\H:\w$ '



Shown following are two more complex examples that include coloring as well:




Command used to achieve this is:

export PS1="\n$C_LIGHTGREEN\u$C_DARKGRAY@$C_BLUE\h $C_DARKGRAY: $C_LIGHTYELLOW\w\n$C_DARKGRAY\$$C_DEFAULT "




No comments:

Post a Comment