The basic way to open a file depends on what kind of file it is

Linux does not have a single "Open" button the way Windows or Mac does. Instead, you choose a program that can read the file type, then tell that program to open the file. A text file opens in a text editor. A photo opens in an image viewer. A document opens in a word processor. The file itself does not care which program you use — it just contains data.

The fastest way is usually to type a command in the terminal. If you are not comfortable with the terminal yet, you can also right-click the file in your file manager and choose an option from the menu. Both methods do the same thing; the terminal is just faster once you learn the pattern.

Before you try to open anything, you need to know where the file is. If you arrived here from the organizing guide, you already have a sense of your folder structure. The file path tells Linux exactly which folder to look in and what the file is called.

Key Takeaways

  • The cat command displays a text file's contents in the terminal, and nano opens it in an editor where you can make changes.
  • Right-clicking a file in your file manager and selecting an option from the menu is the easiest method if you are new to the terminal.
  • The command xdg-open followed by the file path tells Linux to open the file with whatever program is set as the default for that file type.
  • File paths can be absolute (starting from the root of your system) or relative (starting from your current folder), and using relative paths is usually simpler.
  • If a file will not open, the program that handles that file type may not be installed, or the file path may be typed incorrectly.

Opening a text file with cat or nano

The cat command is the simplest way to view a text file. Open your terminal, type cat followed by a space, then the file path, and press Enter. For example, if you have a file called notes.txt in your home folder, you would type: cat ~/notes.txt

The tilde symbol (~) is a shortcut that means "my home folder". Linux will display the entire contents of the file right in the terminal. This works well if the file is short or if you just want to read it quickly. If the file is very long, the text scrolls past and you see only the end.

If you need to edit the file, use nano instead. Type nano ~/notes.txt and press Enter. Nano opens the file in a straightforward text editor inside the terminal. You can move the cursor with arrow keys, type changes, and save by pressing Ctrl+O (the letter O), then Enter, then Ctrl+X to exit. At the bottom of the screen, nano shows you the keyboard shortcuts available.

Using the file manager to open files with a mouse

If you prefer not to use the terminal, open your file manager (usually called Files, Nautilus, or Dolphin depending on your Linux version). Navigate to the folder where your file is stored by clicking through the folder icons. Once you see the file, right-click it.

A menu appears with options like "Open With" or "Open". Click "Open" and Linux will open the file with the default program for that file type. If you want to choose a different program, click "Open With" and select from the list. If the program you want is not in the list, click "Show Other Applications" or "Browse" to see more options.

This method is slower than the terminal for people who open files often, but it requires no typing and works the same way on every Linux system.

Opening a file with xdg-open

The xdg-open command tells Linux to open a file with whatever program is set as the default for that file type. Type xdg-open followed by a space and the file path, then press Enter. For example: xdg-open ~/Documents/report.pdf

Linux looks at the file extension (.pdf, .txt, .jpg, and so on), checks which program is set as the default for that type, and opens the file there. This is useful when you do not care which program opens it — you just want it open. The command works the same way whether the file is a document, image, video, or spreadsheet.

If no default program is set for that file type, or if the program is not installed, you will see an error message. In that case, you can either install the missing program or use "Open With" in the file manager to choose a program manually and set it as the default.

Understanding file paths and how to type them correctly

A file path is the address that tells Linux where to find your file. It starts with a folder name, then lists each folder inside it, separated by forward slashes (/). For example, /home/marcus/Documents/budget.txt means: go to the home folder, then the marcus folder inside it, then the Documents folder inside that, and open the file called budget.txt.

You can write paths in two ways. An absolute path starts with a forward slash and describes the full route from the root of your system. A relative path starts from wherever you are right now in the terminal. If you are already in your Documents folder, you can type just budget.txt instead of the whole path. The tilde (~) is a shortcut for your home folder, so ~/Documents/budget.txt is shorter than typing the full absolute path.

If you are not sure of the exact path, you can type the first few letters of the folder or file name, then press Tab. Linux will complete the rest if it can find only one match. If multiple files match, press Tab again to cycle through them. This is much faster than typing the whole path by hand.

What to do if a file will not open

If you try to open a file and nothing happens, or you see an error, the most common reason is that the program that handles that file type is not installed. For example, if you try to open a .zip file and you do not have an archive manager installed, the file will not open. Check what file type you are trying to open (look at the extension after the dot), then search your system's package manager for a program that handles that type.

The second most common reason is a typo in the file path. If you typed the path by hand, double-check the spelling of each folder and file name. Linux is case-sensitive, which means Notes.txt and notes.txt are two different files. If you are not sure of the exact spelling, use Tab completion as described above.

If the file path contains spaces, you must put the entire path in quotes. For example: cat "~/Documents/My Budget.txt" instead of cat ~/Documents/My Budget.txt. Without the quotes, Linux thinks each word is a separate argument and returns an error.

Opening files from inside a program

You can also open a file by starting the program first, then using its File menu to open the file. Click the program's menu (usually at the top of the window), select "File" or "Open", and a dialog box appears. Navigate to your file and click it, then click "Open". This method is useful if you want to open several files in the same program, or if you are not sure which program to use.

This approach is slower than opening from the terminal or file manager if you know exactly which file you want, but it is the most familiar method for people coming from Windows or Mac.

Frequently Asked Questions

What is the difference between cat and nano?

Cat displays the file contents in the terminal and then returns you to the command prompt — you cannot edit. Nano opens the file in an editor where you can make changes, save them, and exit when you are done. Use cat to read, use nano to edit.

Why does my file path not work even though I typed it correctly?

Linux is case-sensitive, so Notes.txt and notes.txt are different files. Also check that you used forward slashes (/) not backslashes (\). If the path contains spaces, wrap the entire path in quotes. Use Tab completion to avoid typos.

How do I know what program to use to open a file?

The file extension tells you the type: .txt is text, .pdf is a document, .jpg is an image, .mp3 is audio. Use xdg-open to let Linux choose the default program, or right-click in the file manager and select "Open With" to see what programs are available.

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

Yes, but you need the file path to that computer. If the other computer is on your network and set up for file sharing, you can type its address in the file manager's location bar. If it is a remote server, you can use the scp command to copy the file to your computer first, then open it locally.