Setting default path when opening a terminal session
Just run the following command in your terminal:
echo "cd ~/Desktop/Java\ Files" >> ~/.bashrc
The above command will add a new line in your ~/.bashrc
file that contain cd ~/Desktop/Java\ Files
and that will change your default working directory to /home/Varun/Desktop/Java Files
when you will open the terminal.
Reopen the terminal and you will see the difference.
You can add the following line to the end of your ~/.bashrc
cd ~/Desktop/Java\ Files
Although changing the $HOME
variable and calling cd
command (i'll use cmd for short) in .bashrc
file is right answer to your question,
i find it more comfortable to create alias (for example cdh
) which takes me directly to directory i want.
The reason is that all files which configures other programs (Just like .bashrc
for example) stay in default $HOME
directory and i can work in my "cdh
directory" without interuption from theese files.
If i needed to go back to $HOME
directory i can allways use cd
cmd.
In some linux distros the
.bashrc
file is shipped with command or commands which runs or run one or multiple other files intended for that specific use (for example.bash_aliases
)so decide for yourself if you want to use them or not,
in case you want to use them, just use it the same as you use
.bashrc
but with commands inteded for the specified file.
so in .bashrc
(or in .bash_aliases
or whichever file you've chosen)
write following:
alias cdh='cd /home/Varun/Desktop/Java Files'
if you don't like
cdh
alias don't be afraid to use different name but make sure there isn't any other cmd or alias named like this, couse you could make that cmd more or less unusable.You can check if the name is taken by triyng to call it but i would sugest a
type
cmd with argument of name of another cmd.The
type
cmd should tell you if the given cmd is alias, binary file, or bash script, or ......... whatever. And therefore will tell you when cmd doesn't exist. (Which is what you want in this case)