45

I've tried

gnome-terminal -x 'cd /path/to/dir'

and

gnome-terminal -e 'cd /path/to/dir'

but both give me errors when the new terminal opens. How do I get a new terminal to start in a specific directory?

| improve this question | | | | |
57

Use

gnome-terminal --working-directory=/path/to/dir
| improve this answer | | | | |
  • 1
    Curiously, this doesn't seem to work for me in gnome-terminal 3.18.3 (Ubuntu 16.04). The argument is accepted, but Bash in the new terminal opens in $HOME. – Jonathan Hartley Sep 14 '16 at 19:45
  • 1
    This no longer works in Ubuntu 16.04, due to a bug: bugs.launchpad.net/ubuntu/+source/gnome-terminal/+bug/1587154 Please go there and click 'this affects me too' if you'd like it fixed. – Jonathan Hartley Sep 14 '16 at 20:53
  • In the comments to the bug, a workaround is specified to uncheck "Run a custom command instead of my shell." This worked for me. Of course, it won't work if the command you need to run is different than your shell. Your shell can be changed with chsh. – Owen Oct 3 '16 at 13:15
  • preferable with "" gnome-terminal --working-directory="/path/to/dir" – Nicolas Aug 8 '17 at 8:04
  • 1
    @JonathanHartley This bug has been fixed for Ubuntu 16.04.3 LTS running under Kernel 4.14.34-generic – WinEunuuchs2Unix May 21 '18 at 0:25
18

Add the following line to the end of your ~/.bashrc:

cd ~/public_html
| improve this answer | | | | |
  • This method will disable the "open in terminal" from the right click menu in a file browser. It supposed to open current directory in a new terminal. But this command will always redirect you to the ~/public_html directory. – HD189733b Nov 8 '17 at 17:35
  • As a workaround to that cd - should take you to the previous working directory so you could use "open in terminal", your bashrc would immediately forward you to the chosen dir, then cd - would take you back to the dir you wanted to open. Should work! – pbhj May 20 '18 at 21:42
5
sudo apt-get install nautilus-open-terminal 

Restart nautilus and then right click at any directory and select "Open in a Terminal".

| improve this answer | | | | |
4

You can:

  1. Edit/create the file ~/.bashrc and add this line at the end of the file:

    alias cdx='cd /path/to/myfolder'
    

    Save the change and logout/login. When you execute the command "cdx" it will take you to the specified folder.

  2. You can create a shortcut/link that will execute this command:

    • If you use gnome-terminal (ubuntu):

      gnome-terminal --working-directory="/full/path/to/myfolder"
      
    • If you use lxterminal (Lubuntu):

      lxterminal --working-directory="/full/path/to/myfolder"
      
| improve this answer | | | | |
2

you can add nautilus-script like that

Create empty file named as "Open Terminal Here" in

~/.local/share/nautilus/scripts/ # for Ubuntu 13.04 or above
~/.gnome2/nautilus-scripts/      # for Ubuntu 12.10 and below

directory.

Open it and write these lines inside.

#!/bin/bash
gnome-terminal

Make it executable, and right click at any directory in nautilus and select "Scripts > Open Terminal Here" from menu.

| improve this answer | | | | |
1

Open "~/.bashrc" Scroll to the bottom and add a change directory command Example: cd ~/myfolder

Then save and exit. The "~" will take you to your home folder (/home/loginname)

Each time you launch your terminal it reads the .bashrc file so you could also put search paths ETC.....,, in it.

| improve this answer | | | | |
1

This works:

gnome-terminal --tab --title="your title" -- bash -c 'cd /path/to/dir && your_code' &

A few comments:

  • My gnome-terminal version is:
$ gnome-terminal --version
# GNOME Terminal 3.28.1 using VTE 0.52.1 +GNUTLS -PCRE2
  • everything after the bash -c must be wrapped with single quotes
  • you must use the "-c" for the bash option
  • got to use "--" even when the doc says to use "-x" or "-e" (these are deprecated
  • the "-tab" creates a tab in the current terminal window
  • use "-window" to create a new terminal window
| improve this answer | | | | |
  • Thanks! This was the only one working for me after I changed shell to fish – Orkhan Alikhanov Feb 5 at 13:40
0
gnome-terminal --working-directory=/path/to/dir

as

root45 answered

or u can do like this also

if you start gnome-terminal like "gnome-terminal --working-directory=myfolder" it will start with the working directory at ~/myfolder. so you could add a new entry to your menu to use that command instead of the other one.

| improve this answer | | | | |

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.