You can open any file from the terminal by typing its name after a command like `nano` for editing or `evince` for PDFs. But if you’re new to Linux, figuring out how to open file linux can feel confusing at first. Don’t worry—this guide will walk you through every method, from simple commands to graphical tools.
Linux treats files differently than Windows or macOS. There’s no single “open” button. Instead, you choose the right tool for the file type. Let’s start with the basics and build up.
Why Opening Files In Linux Is Different
In Linux, everything is a file—documents, images, even hardware devices. But the system doesn’t assume you want to edit a file when you click it. Instead, you tell it exactly what to do. This gives you more control, but it takes a little learning.
Most file operations happen in the terminal. But don’t worry—you can also use graphical file managers like Nautilus or Dolphin. We’ll cover both approaches.
How To Open File Linux Using The Terminal
The terminal is the most powerful way to open files. Here are the most common commands, broken down by file type.
Open Text Files
Text files are the easiest. Use one of these commands:
- nano filename.txt – Opens in the Nano editor (great for beginners)
- vim filename.txt – Opens in Vim (powerful but has a learning curve)
- cat filename.txt – Prints the file content to the terminal (read-only)
- less filename.txt – Lets you scroll through the file page by page
- head filename.txt – Shows the first 10 lines
- tail filename.txt – Shows the last 10 lines
For example, to open a file called notes.txt in Nano, type nano notes.txt and press Enter. You’ll see the file content ready to edit.
Open Images
For images, you need an image viewer. Common ones include:
- eog image.jpg – Opens in Eye of GNOME
- feh image.png – Lightweight image viewer
- display image.gif – Part of ImageMagick
- gimp image.jpg – Opens in GIMP for editing
If you’re not sure which viewer is installed, try xdg-open image.jpg. This command opens the file with the default application.
Open PDFs
PDFs open with document viewers. Try these:
- evince document.pdf – Default PDF viewer in GNOME
- okular document.pdf – KDE’s document viewer
- zathura document.pdf – Minimalist, keyboard-driven viewer
- acroread document.pdf – Adobe Reader (if installed)
Again, xdg-open document.pdf will use your system’s default PDF viewer.
Open Audio And Video Files
For media files, use media players:
- vlc video.mp4 – Opens in VLC media player
- mpv song.mp3 – Lightweight command-line player
- totem movie.avi – GNOME’s default player
- audacity audio.wav – Opens in Audacity for editing
Open Archives (Zip, Tar, Etc.)
Archives need special commands:
- unzip archive.zip – Extracts a ZIP file
- tar -xvf archive.tar.gz – Extracts a tar.gz file
- file-roller archive.zip – Opens in graphical archive manager
Using The Xdg-Open Command
The xdg-open command is your best friend. It opens any file with the default application for that file type. For example:
xdg-open report.pdf
This will open the PDF in your system’s default viewer. It works for images, text files, web pages, and more. It’s the closest thing to double-clicking in Windows.
You can also use it with URLs:
xdg-open https://example.com
This opens the link in your default web browser.
How To Open File Linux With Graphical File Managers
Not everyone wants to use the terminal. Linux has excellent graphical file managers. Here’s how they work:
Nautilus (GNOME)
Nautilus is the default file manager in GNOME. To open a file, simply double-click it. The system will use the default application for that file type.
To change the default app, right-click the file, select “Properties,” then the “Open With” tab. Choose your preferred application.
Dolphin (KDE)
Dolphin is KDE’s file manager. It works similarly. Double-click to open, right-click for options. You can also preview files by pressing the spacebar.
Thunar (XFCE)
Thunar is lightweight and fast. Double-click opens files. Right-click gives you “Open With” options.
All these managers support drag-and-drop. You can drag a file onto an application icon to open it.
Opening Files With Specific Applications
Sometimes you want to open a file with a program that isn’t the default. Here’s how:
From The Terminal
Just type the application name followed by the file:
gedit document.txt
This opens the text file in Gedit, even if your default text editor is something else.
From The File Manager
Right-click the file, select “Open With,” then choose the application. If it’s not listed, click “Other Application” and browse for it.
Common Problems And Fixes
Even experienced users run into issues. Here are solutions to common problems:
File Not Found
If you get a “No such file or directory” error, check your spelling. Linux is case-sensitive. File.txt and file.txt are different files.
Use the ls command to list files in the current directory. Or use tab completion: type the first few letters and press Tab.
Command Not Found
If you see “command not found,” the application isn’t installed. Install it with your package manager:
- Debian/Ubuntu:
sudo apt install vlc - Fedora:
sudo dnf install vlc - Arch:
sudo pacman -S vlc
Permission Denied
Some files require root permissions. Use sudo before the command:
sudo nano /etc/hosts
Be careful—editing system files can break things if you’re not sure what you’re doing.
Binary Files Open As Garbage
If you try to open a binary file (like an executable) with a text editor, you’ll see gibberish. Use the correct application. For executables, you usually run them directly:
./program_name
Advanced Techniques
Once you’re comfortable, try these advanced methods:
Open Multiple Files At Once
You can open several files with one command:
nano file1.txt file2.txt file3.txt
This opens all three in Nano. Use Alt+Left/Right to switch between them.
Open Files With Wildcards
Use wildcards to open groups of files:
evince *.pdf
This opens all PDFs in the current directory. Be careful—it might open dozens of windows.
Create Aliases For Frequent Commands
If you often open a specific file, create an alias. Add this to your .bashrc file:
alias mynotes='nano /home/username/Documents/notes.txt'
Then type mynotes to open it.
Use A File Manager In The Terminal
Tools like ranger or mc (Midnight Commander) let you browse files in the terminal. They’re great for servers without a graphical interface.
How To Open File Linux On Different Distributions
While the commands are mostly the same, default applications vary by distribution.
Ubuntu And Debian
Ubuntu uses GNOME. Default apps include:
- Text: Gedit
- Images: Eye of GNOME
- PDF: Evince
- Video: Totem
Fedora
Fedora also uses GNOME. Defaults are similar but may include:
- Text: Gedit or GNOME Text Editor
- Images: Loupe
- PDF: Evince
- Video: Totem
Arch Linux
Arch is minimal. You might need to install applications yourself. Common choices:
- Text: Nano or Vim
- Images: Feh or Sxiv
- PDF: Zathura
- Video: MPV
Linux Mint
Mint uses Cinnamon. Defaults include:
- Text: Xed
- Images: Xviewer
- PDF: Xreader
- Video: Celluloid
Opening Files From The Command Line With Environment Variables
You can use environment variables to open files quickly. For example:
nano $HOME/Documents/file.txt
The $HOME variable points to your home directory. This is useful in scripts.
You can also set your own variables:
export WORKDIR=/home/user/projects
nano $WORKDIR/report.txt
How To Open File Linux With Root Privileges
Sometimes you need to edit system files. Use sudo with a text editor:
sudo nano /etc/fstab
Or use gksudo for graphical editors (if installed):
gksudo gedit /etc/hosts
Always be careful when editing system files. Make a backup first:
sudo cp /etc/fstab /etc/fstab.backup
Opening Files With Non-Standard Extensions
Some files have unusual extensions. Here’s how to handle them:
- .md (Markdown) – Open with a text editor or Markdown viewer like
retext - .odt (LibreOffice) – Use
libreoffice file.odt - .csv – Open with LibreOffice Calc or
less - .json – Open with a text editor or
jqfor formatted viewing - .svg – Open with Inkscape or a web browser
Automating File Opening With Scripts
You can write simple scripts to open files. For example, create a file called openreport.sh:
#!/bin/bash
xdg-open /home/user/reports/daily_report.pdf
Make it executable:
chmod +x openreport.sh
Then run it with ./openreport.sh.
How To Open File Linux In A Web Browser
You can open local HTML files or images in a browser:
firefox index.html
Or use xdg-open:
xdg-open image.png
This will open the image in your default browser if no image viewer is set.
Using File Associations To Simplify Opening
You can set default applications for file types. From the terminal, use:
xdg-mime default vlc.desktop video/mp4
This sets VLC as the default for MP4 files. Find the correct MIME type with:
xdg-mime query filetype video.mp4
How To Open File Linux On A Server (No GUI)
On servers without a graphical interface, you rely on terminal-based tools:
- less – View text files
- nano or vim – Edit text files
- links2 or lynx – View HTML files
- pdftotext – Convert PDFs to text, then view with
less - ffplay – Play audio (if you have sound)
For images, you can convert them to ASCII art with jp2a or cacaview.
Troubleshooting: File Opens With Wrong Application
If a file opens with the wrong program, fix it:
- Right-click the file in your file manager
- Select “Properties” or “Open With”
- Choose the correct application
- Check “Set as default” if available
From the terminal, use:
xdg-mime default gedit.desktop text/plain
This sets Gedit as the default for plain text files.
How To Open File Linux With A Single Command Using Aliases
Create aliases for files you open often. Add to .bashrc:
alias todo='nano ~/Documents/todo.txt'
alias logs='less /var/log/syslog'
Then type todo to open your to-do list.
Security Considerations When Opening Files
Be cautious with files from unknown sources. Some file types can execute code:
- .sh – Shell scripts (run with
bash file.sh) - .py – Python scripts
- .desktop – Application launchers
Always inspect scripts before running them. Use cat or less to view the content first.
Frequently Asked Questions
How Do I Open A File In Linux Without A GUI?
Use terminal commands like nano, vim, less, or cat. For binary files, use the appropriate command-line tool.
What Is The Command To Open Any File In Linux?
The xdg-open command opens any file with the default application. For example: xdg-open file.pdf.
How Do I Open A File In Linux From The Terminal?
Type the application name followed by the file path. For example: nano /home/user/file.txt or evince document.pdf.