If you need to run a terminal command on a specific file, opening the terminal and manually typing a long string of cd (change directory) commands to navigate through deeply nested folders can be time-consuming.
Fortunately, the default Ubuntu desktop environment (GNOME) includes a built-in shortcut that allows you to instantly open a terminal window pre-configured to your exact current location in the file manager.
How to Open Terminal from the File Manager
This method bridges the gap between the graphical user interface (GUI) and the command line, saving you from having to type out complex directory paths.
- Open the Files application (also known as Nautilus) from your Ubuntu dock.
- Use the graphical interface to click through your folders until you are inside the directory where you want to run your commands (for example,
/home/user/Downloads/scripts/). - Right-click anywhere in the empty, blank space between your files.
- From the context menu that appears, select Open in Terminal.
A new terminal window will immediately launch. Instead of starting in your default Home directory (~), the terminal prompt will display the exact path of the folder you were just viewing. Any commands you type (like ls or script executions) will execute directly within that specific directory.
Keyboard Shortcut Method
If you prefer keeping your hands on the keyboard, you can achieve the exact same result using a fast keyboard combination.
While viewing the folder in the Files application, simply press Ctrl + Alt + T. The terminal will open, automatically pointing to the directory you are currently viewing.