Seeing some answers in here, and knowing this is an old thread, I still wanted to respond to those stating to put "cd ~" in the
.bashrc file. While that works, that means every interactive non-login shell reads
.bashrc first. That means whether it's the first terminal opened, or every subsequent terminal/bash process is spawned from the initial "login" terminal, you will always end up in the home directory.
You can test this by editing
.bashrc putting the "cd ~" command in it. Exit Windows terminal. Then launch Ubuntu again. You'll be in the home directory. Now, navigate to a different directory within that terminal session and then execute "bash". You'll end up in your home directory which might not be what you wanted.
This same issue happens if you are using Visual Studio code. In VSC, you have the ability to create terminal sessions. Many are expecting that session to open up in whatever directory they launched VSC from (mostly a project they are working on). However, that will execute the commands in
.bashrc which means you'll end up in your home directory.
.bashrc is suited for commands that are specific to the Bash shells. So, putting aliases and other Bash related functions into
.bashrc is good.
A better place to put the "cd ~" is in the
.profile file. This way, upon the initial terminal bash launch, it will execute the "cd ~" command in
.profile. If you then launch VSC from a different directory, when you create a terminal session within VSC, it will stay in the directory you launched VSC from which is what most programmers would expect.
After doing this and removing "cd ~" from
.bashrc, launch a new terminal session. You'll be in your home directory. Then, navigate to a different directory and type "bash". You'll start a new bash session but stay in the directory you were last in.
If you launch a new Ubuntu terminal inside Windows Terminal, you'll be back in your home directory since it's a brand new Terminal login session.
Hope that helps!