How to Open the Terminal to a Specific Directory in Linux

00_lead_image_open_terminal_to_specific_directory

By default, new Terminal windows open to your Home directory. However, if there’s another directory you use often that you want immediate access to when you open the Terminal, there’s an easy way to set this up.

RELATED: Beginner Geek: How to Start Using the Linux Terminal

The .bashrc file in your Home directory contains commands that run when you open a Terminal window. So, we can add a cd command to change to a specific directory as soon as the Terminal window opens. To do this, press Ctrl+Alt+T to open a Terminal window. As we mentioned, you are in your Home directory by default, which is where you want to be right now.

We’re going to edit the .bashrc file, so type the following command to open it. You can use whichever text editor you want to use, but we’re going to use gedit in our example.

gedit .bashrc

01_opening_bashrc_file

Scroll to the bottom of the .bashrc file and add the following command.

cd ~/HTGArticles

The tilde character (~) is a shortcut for your Home directory, which in our example, is /home/lori. So, the full path for the directory in the above command is /home/lori/HTGArticles.

Replace ~/HTGArticles with the directory you want to open when you open a Terminal window.

The following line is a comment we added above the cd command, explaining what the command is doing. You don’t have to add a comment, but it helps make the .bashrc file easier to understand. The pound sign (#) at the beginning of a line indicates that line is a comment.

# Open to HTGArticles directory

Once you’ve added the command to the file, click “Save” in the upper-right corner of the window to save the file.

02_adding_cd_command_to_bashrc

Close the .bashrc file by clicking the “X” button in the upper-left corner of the window.

03_closing_gedit

You must restart the Terminal window for this change to take effect. To close the Terminal window, either type exit at the prompt and press Enter, or click the “X” button in the upper-left corner of the window.

04_closing_terminal_window

Now, press Ctrl+Alt+T to open the Terminal again. You are immediately in the directory you specified in the .bashrc file. You can still navigate to any other directory, but this is helpful if you work in this directory the most.

05_terminal_window_open_to_specific_directory

If you use both Nautilus and the Terminal to work with files, you can open a specific directory in Nautilus from the Terminal as well as open a Terminal window to a specific directory from Nautilus.

Lori Kaufman is a writer who likes to write geeky how-to articles to help make people's lives easier through the use of technology. She loves watching and reading mysteries and is an avid Doctor Who fan.