How to open a file from Mac Terminal [Easy Guide]

Milan Stanojevic
by Milan Stanojevic
Deputy Editor
0 Comments
Download PDF
Affiliate Disclosure

  • If you’re a Mac user, you probably encountered Terminal at least once.
  • The Terminal can be a great tool, and in this article, we’ll show you how to open a file in Terminal.
  • Want to learn more about macOS? For more information, visit this special Mac OS article.
  • For more guides on how to open certain files, be sure to visit our File opener Hub.
open file in terminal

The Terminal can be an incredibly useful tool, especially for advanced users. Unfortunately, many users aren’t familiar with the Terminal at all.

In this article, we’re going to change that, and we’re going to show you how to open a file in Terminal. It’s easier than you think, so let’s get started.

Ad

How can I open a file in Terminal?

1. Use the open command

  1. Navigate to Applications > Utilities.
  2. Start the Terminal.
    open terminal open file in terminal
  3. Run the following command:
    open ~/Desktop/filename.mp4

After running this command, you’ll open the selected file with the default application for that file type.

You can also open multiple files simply by doing the following:

  1. Navigate to the folder where the files are stored using the cd command in Terminal.
  2. Now run the following command:
    open "file1.mp4" "file2.mp4" "file3.mp4"

You can also open all files with the same file type by using the following command:

open ~/Desktop/*.jpg

By using this command, you’ll open all .jpg files that are located in the Desktop folder.

To open a file with specific software, you need to slightly adjust the command by adding the -a parameter followed by the name of the software that you want to use to handle the file.

In practice, the command would look something like this:

open -a "QuickTime Player" ~/Desktop/filename.mp4

If you want, you can even use a specific path for the app that you want to use to open the file. You can do that like this:

open -a /path/to/chosen_app.app filename.mp4

Ad

You can also open a file in the Terminal but choose not to bring the file to the foreground. This can be done with the -g parameter like this:

open -g ~/Desktop/filename.mp4


2. Edit the .bash_profile file

  1. Locate the ~/.bash_profile file and open it.
  2. Add the following line:
    alias WindowsReport='open -a TextEdit'
  3. Save changes.

Now you have created an alias, and you can use to quickly enter certain commands. This can be useful if you’re working with multiple files or long file paths.

To use the alias to open a certain text file, do the following:

  1. Open the Terminal.
  2. Run the following command:
    WindowsReport textfile.txt

Basically, by using this method you can make commands shorter and easier to remember. You can create various aliases by using the commands that we mentioned above.

Also, you can use the Tab key while typing the alias name to quickly add it, which will make the process a lot faster.

Opening files in Terminal isn’t that hard, and you should be able to do it with ease after following the instructions from this article.

Ad