How can I open a terminal in the desktop directory?
Solution 1
Simply add the following to ~/.bashrc
if [[ $PWD == $(realpath ~) ]]; then
cd ~/Desktop/
fi
My solution changes the directory to the desktop even when you press ctrl + alt + t
(default keyboard shortcut to open terminal)
My solution check the working directory and if it is the same as ~
, then cd
to Desktop
Note: Macerarius' solution always opens in a certain path
(even when you click "Open in Terminal" inside a folder in Nautilus)
Solution 2
Alternatively
Not literally what you asked for, but an alternative solution is to add the command:
/bin/bash -c "cd ~/Desktop && gnome-terminal"
to a shortcut of your choice. On pressing the shortcut, a terminal window will open with the Desktop as working directory.
Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
/bin/bash -c "cd ~/Desktop && gnome-terminal"
...to a shortcut of your choice.
The (subjective) advantage is that you don't need to touch ~/.bashrc
and that the default directory will be unchanged.
Note
The exact directory (-name) per language may vary. In Dutch: ~/Bureaublad
Solution 3
Two options:
Edit the file
~/.bashrc
and add this line at the end of the file:cd /path/to/folder
Save the change and logout/login. Terminal should now open the specified directory by default.
Edit the file
~/.bashrc
and add an alias to quickly change the directory in terminal:alias cdd="cd /path/to/folder"
Save the change and logout/login. Open terminal, cdd
takes you quickly to the specified directory.
Related videos on Youtube
Ricardo Magalhães Cruz
MS in Applied Mathematics BS in Computer Science
Updated on September 18, 2022Comments
-
Ricardo Magalhães Cruz over 1 year
I am using Ubuntu 16.04 and Nautilus 3.14.3 (default version).
There is an open terminal context menu when right- clicking on the desktop. It opens the terminal with
~
as working directory, but I'd like it to open in~/Desktop
.I think there was a
dconf
option to change this behavior, but I cannot find anything related under/org/gnome/nautilus
.-
Ricardo Magalhães Cruz almost 8 yearsPlease give me some time to try it and see which solution I find more ergonomic...
-
-
Ricardo Magalhães Cruz almost 8 yearsDo you know if I can edit /usr/share/applications/gnome-terminal.desktop so that it opens in ~/Desktop. I have tried a few things like Path=, but it did not work... :P It would probably be more ergonomic for me for the Dask terminal icon to open in my desktop...
-
Jacob Vlijm almost 8 years@rpmcruz sure, but it has no influence on how the right- click option works. Right- clicking surpasses the .desktop file.
-
Ricardo Magalhães Cruz almost 8 yearsI know, but I think it is easier for the dash icon to automatically open me in ~/Desktop. Most of my work is there... (I have tried editing the .desktop, but was unsuccessful, I will try when I have some time...)
-
Jacob Vlijm almost 8 yearsI can add it tonight, but I need to edit the wnswer on my mobile on a too small screen :)
-
Harrison Cramer over 5 yearsThanks. This is probably the easiest solution.