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?
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?
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.
. "~/.bashrc"
cd ~/something
– MeltingPoint
Jun 24 '23 at 17:47
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)
While putting cd ~/Desktop/Java\ Files
into the .bashrc
file does work, it has the terrible side-effect of overriding the Nautilus Open in Terminal action, so you can no longer open any other sub-folder in a terminal.
My solution is to change the Keyboard Shortcut in Settings for Ctrl+Alt+T to run this command:
/usr/bin/gnome-terminal --working-directory="/home/butch/Documents"
This will open new terminal windows in my Documents
folder, while allowing Nautilus to open new terminal windows wherever.
Note this command does not accept ~/Documents
, the full path must be specified.
Add this to your ~/.bashrc
file.
If you open terminal from nautilus in your home directory, it will unfortunately still cd. I'm not sure how escaping works, but this might not work if your current directory or home directory has unescaped characters.
if [ "$PWD" == "$HOME" ]; then cd Desktop/Java\ Files/; fi
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.
First you need to know what shell you are using. Acces the rc
file of that shell. In normal Ubuntu shell, it is ~/.bashrc
and in zsh shell it is ~/.zshrc
. Then add a line at the bottom that says:
cd <Destination>
For a windows destination, use /mnt/<harddrive>
. For a Ubuntu destination, just use ~<destination>
.
Example(zsh shell and windows path):
vim ~/.zshrc
cd /mnt/c/Desktop
Hope this helps.
GNOME Terminal has an option within the user's profiles called "Preserve working directory" and probably this is what you need to tweak.
I'm posting this here, because one more suitable Terminal opens in incorrect directory is marked as duplication of this one.