15

I am new to Ubuntu.

Whenever I open a terminal my current working directory /home/Varun (as found by typing pwd).

Is there any way I can make the terminal's path to be set as /home/Varun/Desktop/Java Files when it opens?

28

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.

6

You can add the following line to the end of your ~/.bashrc

cd ~/Desktop/Java\ Files

0

Just to add

If someone is using zsh shell than

nano ~/.zshrc ( open the configuration file)

and at bootom add

cd ~/Desktop/Java\ Files

so the tweak is what ever shell you are using (echo $0 ) just add the command you usually use and it will be executed.

0

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)

  • Sorry if i made any mistake. Im not a native english speaker. – Tomáš Růžička Nov 5 '18 at 12:47

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.