Opening a file from cmd means telling your computer to launch it using text commands instead of clicking

The command line can open any file on your computer — a document, image, video, or program — by typing a single instruction. The command itself is straightforward: you type the program name, then the file path, then press Enter. Windows and Mac use slightly different commands, but the logic is identical. Most people never need to do this, but it becomes useful when you are automating tasks, troubleshooting, or working on a remote computer where you cannot click.

The most common reason to open a file from cmd is to launch it with a specific program rather than the default one. For example, you might open a text file in Notepad instead of Word, or open an image in a command-line tool instead of your photo viewer. Another reason is to open a file that is buried several folders deep without navigating through them manually.

Key Takeaways

  • On Windows, type start filename.txt to open a file with its default program, or start notepad filename.txt to open it in a specific program.
  • On Mac or Linux, type open filename.txt to open with the default program, or open -a AppName filename.txt to choose the program.
  • If the file is not in your current folder, you must include the full path: start C:\Users\YourName\Documents\filename.txt on Windows.
  • File paths with spaces must be wrapped in quotes: start "C:\My Documents\my file.txt"
  • Use cd to navigate to the folder containing your file first, which makes the command shorter and easier to type.

Opening a file with its default program on Windows

On Windows, the start command opens a file using whatever program is set as the default for that file type. If you have a file called report.pdf and your default PDF reader is Adobe Reader, typing start report.pdf will launch Adobe Reader and load that file.

First, open Command Prompt by pressing Windows key + R, typing cmd, and pressing Enter. Navigate to the folder where your file lives by typing cd followed by the folder path. For example, if your file is in Documents, type cd C:\Users\YourName\Documents and press Enter. Then type start filename.pdf (replace filename.pdf with your actual file name) and press Enter. The file will open in your default program.

If you do not know the exact path to your file, you can find it by opening File Explorer, navigating to the file, right-clicking it, and selecting Properties. The location will be shown at the top. Copy that path and paste it into your command.

Opening a file with a specific program on Windows

Sometimes you want to open a file with a program other than the default. For example, you might want to open a .txt file in Notepad instead of Word. The command is start programname filename. Type start notepad myfile.txt to open myfile.txt in Notepad, or start mspaint image.jpg to open an image in Paint.

The program name must be one that Windows recognizes. Common ones are notepad, mspaint, calc (calculator), and wordpad. If you want to use a program that is not in Windows' standard list, you need the full path to the program's executable file. For example, start "C:\Program Files\Adobe\Reader\AcroRd32.exe" myfile.pdf will open myfile.pdf in Adobe Reader if it is installed in that location.

If the program name or file path contains spaces, wrap the entire path in quotes. Type start "C:\Program Files\My Program\program.exe" "C:\Users\YourName\My Documents\myfile.txt" to open myfile.txt with a program whose path includes spaces.

Opening a file on Mac or Linux

On Mac and Linux, the command is open instead of start. Open Terminal (on Mac, press Command + Space, type Terminal, and press Enter; on Linux, right-click the desktop and select Open Terminal). Navigate to your file's folder using cd, then type open filename.txt and press Enter. The file will open in its default program.

To open a file with a specific program on Mac, type open -a AppName filename.txt. For example, open -a TextEdit myfile.txt opens myfile.txt in TextEdit. The app name must match exactly as it appears in your Applications folder. On Linux, use the program name directly: gedit filename.txt opens the file in gedit, or vim filename.txt opens it in Vim.

Like Windows, if your file path or program name contains spaces, wrap it in quotes: open -a "Visual Studio Code" "My Documents/my file.txt"

Using the full file path instead of navigating first

You do not have to navigate to a file's folder before opening it. You can type the entire path in one command. On Windows, type start C:\Users\YourName\Documents\Reports\Q4report.pdf to open Q4report.pdf without first navigating to the Reports folder. On Mac or Linux, type open /Users/YourName/Documents/Reports/Q4report.pdf.

This method is faster if you only need to open one file, but it requires you to know or copy the exact path. The path must be accurate — if you misspell a folder name or use the wrong slash direction (Windows uses backslashes, Mac and Linux use forward slashes), the command will fail and you will see an error message saying the file was not found.

A practical shortcut: in File Explorer (Windows) or Finder (Mac), you can hold Shift and right-click a file, then select Copy as Path. This copies the full path to your clipboard, and you can paste it directly into your command line without typing it manually.

Handling file paths with spaces and special characters

File names and folder names with spaces cause problems in the command line because the space tells the command where one argument ends and another begins. If you type start C:\Users\YourName\My Documents\myfile.txt, the command line thinks you are trying to open a file called C:\Users\YourName\My and will fail.

The solution is to wrap the entire path in double quotes. Type start "C:\Users\YourName\My Documents\myfile.txt" instead. The quotes tell the command line to treat everything inside as a single path, spaces and all. This works on both Windows and Mac/Linux.

Other special characters like parentheses, ampersands, and percent signs can also cause problems. When in doubt, wrap the path in quotes. It does not hurt to use quotes even when the path has no spaces, so if you are unsure, quotes are always safe.

Troubleshooting when the file will not open

If you type a command and nothing happens, or you see an error message, the most common cause is a typo in the file path or file name. Check that every folder name and the file name are spelled exactly right, including capitalization on Mac and Linux (Windows does not care about capital letters in paths). Use Tab to auto-complete: type the first few letters of a folder or file name and press Tab, and the command line will finish it for you if it finds a match.

If you see "The system cannot find the file specified", the file does not exist at the path you typed, or you are in the wrong folder. Type dir on Windows or ls on Mac/Linux to list all files in your current folder and verify the file name is there. If it is not, navigate to the correct folder using cd.

If you see "The system cannot find the path specified", a folder in your path does not exist. Double-check the folder names, especially for typos. If you copied the path from File Explorer, paste it into Notepad first to make sure no extra characters were copied.

Frequently Asked Questions

Can I open a file that is on a different drive?

Yes. On Windows, type the drive letter first: start D:\folder\filename.txt opens a file on the D drive. On Mac and Linux, all drives appear as folders under a single root, so you use the same syntax as any other path.

What if I do not know the program name?

On Windows, right-click the file in File Explorer, select Open With, and look at the program names listed. Use that exact name in your command. On Mac, open the file in Finder, press Command + I to open Info, and look under Open With. On Linux, type which programname to find the full path to a program if you know its name.

Can I open multiple files at once?

Yes. Type start file1.txt file2.txt file3.txt on Windows, or open file1.txt file2.txt file3.txt on Mac/Linux. Each file will open in its default program, usually in separate windows.

Why would I use this instead of just double-clicking the file?

Double-clicking is faster for opening one file. The command line is useful when you are writing scripts to automate tasks, opening files on a remote computer, or opening a file with a non-default program without navigating menus.