For most Mac users, the preferred way of opening files or folders is through the Finder app. But that’s not the only way you can navigate and access the file or folder system – you can go through a command line. Terminal is the default gateway to that command line, which doesn’t require you to point or click anything – just type a command and your Mac and it will execute the command. 

There are several situations where Terminal comes in handy when accessing a file or folder. For instance, if you’re a developer or command-line user and work with Terminal. The app also comes in handy where macOS is the server software and Terminal is the only way to navigate the operating system.

Table of Contents

    In this guide, we’ll show you how to open a file or folder in Terminal on your Mac. 

    How to Open a File in Terminal

    You can use Terminal to open a file through its default/specific app or through the text editor. 

    When you open Terminal, you’ll see something like this: 

    Last login: Mon Sep  6 17:03:20 on ttys000
    beeagey@Elsiers-Air ~ % 

    Open a File in Terminal Through Its Default Application

    You can open a file using the file’s default application.

    1. Select Go > Utilities.
    1. Next, select Terminal to open the application. 
    1. Right-click the file and select Copy. Alternatively, you can drag the file to the Terminal window to add to the command line.
    1. In the Terminal window, type Open [file pathway you copied] and hit the Return button for the command to take hold. 

    Note: If you make a mistake in your command pathway, you’ll get the “No such file or directory exists” message. 

    Open a File in Terminal Using a Specific Application

    If you want to open your file in Terminal using an application you specify, you’ll still need the file pathway that you copied earlier and the name of the app you’re using. 

    1. In the Terminal window, type Open -a “App Name” [file pathway]. For example, you can enter Open -a “Preview” /Users/beeagey/Desktop/GOOD\ OR\ BAD\ HUSTLE.jpg.
    1. Press the Return button for the command to take hold. 

    Open a File in Terminal Using the Text Editor

    You can use your Mac’s text editor to open files via Terminal and edit rich text documents created in Word or OpenOffice and other word processing apps.

    1. Open Terminal and enter this command: Open -a Text Edit [file pathway]. For example: Open -a TextEdit /Users/beeagey/Desktop/How\ to\ Open\ a\ File\ or\ Folder\ in\ Terminal\ on\ Mac.docx.
    1. Presst Return run the command and open the file. 

    How to Open a Folder in Terminal

    You can open a folder in Terminal to see what’s in the folder. 

    1. Select Go > Utilities > Terminal.
    1. Enter open /path/to/Directory syntax to open the folder. For example, you can type Open /Users/beeagey/Desktop/screenies.

    Note: If you enter the wrong folder pathway, like /Users/beeagey/screenies, you’ll get a message like the one below:

    The file /Users/beeagey/screenies does not exist.

    beeagey@Elsiers-Air ~ %

    You can also access specific folders using several other commands as follows. 

    • Root directory: Open /
    • Home folder: Open ~. To get the ~ symbol, press Shift + N.
    • Current working folder in Finder: Open . .
    • Open an app without using Finder: Open /Applications/nameofapplication.app. For example, if you want to open Safari, enter Open /Applications/Safari.app.

    Open a Folder in Terminal Using a Shortcut Menu

    If you want to make a Finder directory the current working directory, you can reverse the situation using a shortcut menu.

    1. Select Apple menu > System Preferences.
    1. Next, select Keyboard.
    1. Go to the Shortcuts tab. 
    1. Select Services.
    1. Find the New Terminal at Folder option.
    1. Select a folder within Finder, open the Services menu and select New Terminal at Folder. You’ll be doing this whenever you want to switch between Terminal and a GUI.

    Control How You Open Files and Folders on Your Mac

    You can use Terminal for all sorts of different tasks on your Mac. Some of them can be done in Finder but it’s much faster when you go through Terminal. You can also access deep-rooted parts of macOS that you wouldn’t access from Finder without specialist apps. 

    Check out more ways to use Terminal to kill a process using Terminal on macOS, identify network settings, or update Mac apps.

    Was this guide helpful? Share your thoughts in a comment.