How to open a file via Mac Terminal


If you are working on the Mac Terminal and want to see the contents of a file on an external app like TextEdit (default text editor for macOS) then you can make use of the open command.


Open File in TextEdit

% open -a TextEdit ~/Desktop/sample.txt
Open File in Sublime Text using Terminal

In a similar way if you have other Text Editors installed on your Mac you can open files with them as well,


Open File in Sublime Text

% open -a TextEdit ~/Desktop/sample.txt
Open File in TextEdit using Mac Terminal

Open File in Default Text Editor

% open  ~/Desktop/sample.txt

You do not need to pass in any options with open command to open the file in the default text editor.

Note: You can open any type of file using the open command, let's try to open an mp4 video file.

% open  ~/Documents/holiday.mp4
Open Video file from Terminal

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap