October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Open a File in the Linux Terminal

Use xdg-open for a file’s default desktop application, less to read text in the terminal, and nano to edit. This guide covers paths, spaces, hidden names, SSH sessions, permissions, and file-association errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Open” can mean three different things in Linux: launch a file in its normal desktop application, read it inside the terminal, or edit it. Use xdg-open file for the first, less file for read-only viewing, and nano file for editing.

xdg-open report.pdf
less notes.txt
nano notes.txt

Open a file with its default desktop application

On a Linux desktop, run:

xdg-open path/to/file

xdg-open asks the desktop environment to use the application associated with that file type. A PDF might open in a PDF viewer, an image in an image viewer, and an HTML document in a browser. The exact application depends on your installed software and configured file associations; it is not fixed across distributions. See the xdg-open manual.

Common examples

xdg-open report.pdf
xdg-open image.png
xdg-open /home/alex/Documents/report.pdf
xdg-open "./My Documents/notes.txt"
xdg-open .

The final command opens the current directory in the default file manager. A period (.) means the current working directory.

xdg-open is intended for a graphical desktop session. It may not be useful from a headless server, a container, or an SSH session without graphical access, and its manual advises against running it as root.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
TECH STORE ON Kali Linux Bootable USB + Linux Command Cheat Sheet Mousepad – Cybersecurity Workstation Kit
  • Bootable Kali Linux Environment – No installation required
  • Large Linux Command Reference Mousepad (Desk Size)
  • Ideal for Cybersecurity Labs & Training
  • Plug & Boot on Compatible Systems
  • Complete 2-Item Bundle – Functional & Practical

Read a text file inside the terminal

Use less for interactive reading

For a file that may be longer than one screen, use:

less filename.txt

less leaves the file unchanged and lets you move through it without flooding the terminal. Typical controls are:

  • Space — next page
  • b — previous page
  • Up/Down — move one line
  • g — beginning of the file
  • G — end of the file
  • /word — search for a word
  • n — next search match
  • q — quit and return to the shell

Ubuntu’s command-line tutorial recommends less when output does not fit comfortably on one terminal screen: Ubuntu Linux command-line tutorial.

Use cat for short text

cat filename.txt

cat writes file contents to standard output. It is convenient for a short file or for sending content into another command, but a large file can scroll past the terminal quickly. The GNU Coreutils documentation and Ubuntu cat manual describe its behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Display only part of a file

For quick inspection, use the GNU Coreutils utilities:

head -n 20 filename.txt
tail -n 20 filename.txt
tail -f application.log
  • head prints the beginning of a file.
  • tail prints the end.
  • tail -f keeps displaying new data appended to a growing file, which is useful for logs; press Ctrl+C to stop it.

Reference: GNU Coreutils manual.

Edit a file from the terminal

Nano: the beginner-friendly option

nano notes.txt

Nano opens the file in the terminal and may create it when the path does not exist. Standard Nano builds show shortcuts along the bottom; commonly, Ctrl+O saves and Ctrl+X exits. Because this is an editor, saving changes the file.

Vim: a more advanced alternative

vim notes.txt

Vim is powerful but has a steeper learning curve. Neither editor is guaranteed to be installed on every minimal Linux system.

Rank #2
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (8) Canvas for Bedroom Living Room Decor 08x12inch(20x30cm) Unframe-style
  • NOTE: All poster prints may vary slightly from what you see on your screen due to the resolution and colour profile of your device. These prints look AMAZING when displayed in a frame or straight on the wall.
  • QUALITY: The poster is printed on canvas. It is waterproof,moisture proof and high tensile strength.The poster has rich printing color and fine texture.
  • DECORATION: TOP MODERN! Really eye-catching! Ideal for all modern graphic & photographic designs. Your wall / room gets very special lightness & beauty.
  • FEATURES: We are good at making canvas posters, making high-quality posters is our pursuit, Different from paper posters, canvas posters have better quality and longer shelf life.
  • If you are not satisfied with our print paintings, please feel free to contact us.

Use paths safely

Relative and absolute paths

A relative path starts from the directory shown by pwd; an absolute path starts at the filesystem root:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
pwd
ls
xdg-open ./report.pdf
xdg-open ../Downloads/report.pdf
xdg-open /home/alex/Downloads/report.pdf
less ~/Documents/notes.txt

. means the current directory, .. its parent, ~ your home directory, and / the filesystem root.

Spaces and shell-special characters

Quote a path containing spaces or characters such as parentheses and ampersands:

xdg-open "My Report.pdf"
less "Project Files/notes (draft).txt"

You can also escape spaces with backslashes:

xdg-open My Report.pdf

Without quoting or escaping, the shell treats each space-separated word as a separate argument. Tab completion is often easiest: type part of the name and press Tab.

Hidden files

Unix names beginning with a dot are hidden. List them with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -la

Then open one by specifying its path, for example:

less ~/.bashrc
xdg-open ~/.some-document

Be cautious when editing configuration files such as ~/.bashrc; a syntax mistake can affect later shell sessions.

Names beginning with a hyphen

A name such as -report.pdf can be mistaken for an option. Prefix it with ./ or use an absolute path:

Rank #3
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (9) Canvas for Living Room Bedroom Decor 12x18inch(30x45cm) Unframe-style
  • NOTE: All poster prints may vary slightly from what you see on your screen due to the resolution and colour profile of your device. These prints look AMAZING when displayed in a frame or straight on the wall.
  • QUALITY: The poster is printed on canvas. It is waterproof,moisture proof and high tensile strength.The poster has rich printing color and fine texture.
  • DECORATION: TOP MODERN! Really eye-catching! Ideal for all modern graphic & photographic designs. Your wall / room gets very special lightness & beauty.
  • FEATURES: We are good at making canvas posters, making high-quality posters is our pursuit, Different from paper posters, canvas posters have better quality and longer shelf life.
  • If you are not satisfied with our print paintings, please feel free to contact us.
less ./-report.txt
xdg-open ./-report.pdf
xdg-open /home/alex/-report.pdf

The xdg-open manual specifically recommends an explicit relative path, an absolute path, or a file URL for this case.

Find out what a file is

When the type is unknown, inspect the path before choosing a command:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -l path/to/file
file path/to/file

Use less for readable text, xdg-open for a desktop-associated format, or a format-specific utility for archives, media, and other data. Avoid sending an unknown binary file through cat; the output can be unreadable and may temporarily disturb terminal display behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a command fails

The path is wrong or the file is missing

Check your location and spelling:

pwd
ls -l path/to/file

Linux paths are generally case-sensitive. Check for missing quotes around spaces and remember that a relative path is resolved from the current directory. To search your home directory:

find ~ -name 'report.pdf'

xdg-open reports a failure when the supplied file does not exist, as documented in its manual.

You lack permission

ls -l shows the file permissions. Reading a file requires read permission on the file and access to each directory in its path. Opening a program also requires the appropriate execute permission. Do not treat sudo as a general fix, especially for xdg-open, which is not recommended as root.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is no graphical session

On a server, virtual console, container, or ordinary SSH connection, use terminal tools such as:

less file.txt
nano file.txt

If you need to view the file on your own computer, copy it from the remote host with a separate transfer command, for example:

scp user@server:/path/to/file .

Running xdg-open over SSH acts in the remote environment; it does not automatically open the file on your local desktop.

No default application or the wrong application

If no handler is configured, install a suitable application or set a default in your desktop environment. For diagnosis, query the detected MIME type and its default handler:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
xdg-mime query filetype path/to/file
xdg-mime query default "$(xdg-mime query filetype path/to/file)"

This advanced check is useful when an extension is misleading, the MIME type is unexpected, or the configured application is unavailable. For a one-off opening, you can invoke a known program directly, such as evince report.pdf, gedit notes.txt, or firefox page.html; these names are examples, not universal commands.

What about gio open or open?

gio open file is a common alternative on GNOME systems, but it depends on the GNOME/GIO stack and may be absent elsewhere. KDE also has desktop-specific utilities. xdg-open is the more portable desktop-oriented recommendation when it is installed.

Do not assume that bare open file is the Linux equivalent of macOS. Linux distributions and packages may assign that name different behavior.

Quick Recap

SaleBestseller No. 1
TECH STORE ON Kali Linux Bootable USB + Linux Command Cheat Sheet Mousepad – Cybersecurity Workstation Kit
TECH STORE ON Kali Linux Bootable USB + Linux Command Cheat Sheet Mousepad – Cybersecurity Workstation Kit
Bootable Kali Linux Environment – No installation required; Large Linux Command Reference Mousepad (Desk Size)
$25.18
Bestseller No. 2
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (8) Canvas for Bedroom Living Room Decor 08x12inch(20x30cm) Unframe-style
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (8) Canvas for Bedroom Living Room Decor 08x12inch(20x30cm) Unframe-style
If you are not satisfied with our print paintings, please feel free to contact us.
$17.90
Bestseller No. 3
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (9) Canvas for Living Room Bedroom Decor 12x18inch(30x45cm) Unframe-style
Linux Commands Cheat Sheet Chart Poster Linux Quick Reference (9) Canvas for Living Room Bedroom Decor 12x18inch(30x45cm) Unframe-style
If you are not satisfied with our print paintings, please feel free to contact us.
$21.90

Quick reference

Goal Command Notes
Default graphical application xdg-open file Needs a working desktop session
Read text interactively less file Press q to quit
Print a short text file cat file Writes contents to standard output
Show beginning head file GNU/Linux utility
Show end tail file Useful for logs
Follow a growing log tail -f file Stop with Ctrl+C
Edit text nano file Saving changes the file
Open the current folder xdg-open . Uses the default file manager

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.