Terminal app is the command line interface in Mac for executing commands. The app is useful to get things done from the command prompt like creating a new text file or flushing system’s DNS cache. However, Terminal app will open with the user folder in the prompt by default. This will be inconvenient to change the directory every time when you launch the app. In this article, we will explain how to open Terminal from a folder in Mac so that you can directly run commands within that directory.
Problem with Default Terminal Prompt
Open Finder app and go to “Utilities” folder. Here you can find the Terminal app, double-click on it and open the app.
As you can see, Terminal app opens with your username (home) folder as a default prompt.
Let us say, you want to create a new folder called “test” in your desktop. For this, first you need to change the directory with CD command.
Now, the prompt will be changed to desktop and you can create a new folder with mkdir command as below.
This looks easy to change the directory in Terminal when you want to do one or two actions. But it will be waste of time to change the prompt every time when you are doing a project in a specific folder like /Desktop/Project. Fortunately, Mac offers an option to open Terminal with the required folder in the prompt using “New Terminal at Folder” service.
Enable New Terminal at Folder Service
First, follow the below instructions to enable a “New Terminal at Folder Service”.
- Click the Apple menu and go to “System Preferences…” option.
- You will find lot of icons and click on the “Keyboard” icon to open keyboard preferences in Mac.
- When you are in keyboard preferences screen, go to “Shortcuts” tab and then select “Services” from the sidebar. Scroll down a bit on the list of options and enable “New Terminal at Folder” under “Files and Folders” section. You can also enable “New Terminal Tab at Folder” to open a new Terminal tab from the selected folder.
That’s all!!! Now, you have enabled the required services and the next step is to test Terminal app from a folder. Note that you can also go to the “Services” section of keyboard preferences from “Finder > Services > Services Preferences…” menu in Finder app.
Open Terminal from Folder
We have a folder named “Project” in “Desktop” and we go to this folder in Finder app.
- After selecting the “Project” folder, navigate to “Finder > Services” menu.
- Here you will see the services you have enabled in above section and click on “New Terminal at Folder” option.
- This will open Terminal app from that folder in the prompt as shown below.
- You can use “New Terminal Tab at Folder” service to open a new Terminal tab from the selected folder.
Instead of going through “Finder > Services” menu, you can also choose the services from toolbar actions list after selecting the required folder in Finder app.
Now, you can execute any command in Terminal like creating a text file or creating a directory to work within the “Project” folder.
Note: Sometimes, you may get confused which directory you are in the Terminal app. Simply type, pwd and press enter. This is a Print Working Directory command which will display the full directory path of current location.