In Linux, there are multiple ways to open a file depending on the type of file (text, image, video, etc.) and the environment you're using (command line or GUI). Here's a breakdown by method and file type:
π From the Command Line (Terminal)
π Text Files
- 
cat filenameβ Displays the file content in the terminal. - 
less filenameormore filenameβ Opens the file in a paginated viewer. - 
nano filenameβ Opens in the nano text editor. - 
vi filenameorvim filenameβ Opens in vi or Vim. - 
gedit filenameβ Opens in the GNOME graphical editor (if installed). - 
code filenameβ Opens in VS Code (if installed). 
π· Image Files
- 
eog filenameβ Eye of GNOME image viewer. - 
feh filenameβ Lightweight terminal-based image viewer. - 
display filenameβ From ImageMagick. - 
xdg-open filenameβ Opens with default associated application. 
π¬ Video/Audio Files
- 
vlc filenameβ Opens with VLC player (if installed). - 
mpv filenameβ Lightweight media player. - 
xdg-open filenameβ Uses the default media player. 
π PDF Files
evince filenameokular filenamexdg-open filename
π§ Generic Open Command
- 
xdg-open filenameβ Opens any file with the default app for that file type. - 
open filenameβ macOS equivalent, works on some Linux setups if aliased. 
πΌοΈ From the GUI (Graphical User Interface)
You can:
- Double-click the file in a file manager (Nautilus, Dolphin, Thunar, etc.)
 - Right-click β "Open With" to choose an application.
 - Drag and drop the file into an open application window.
 
π§ͺ Bonus: Scripting (in bash)
#!/bin/bash
file="example.txt"
if [ -f "$file" ]; then
    xdg-open "$file"
else
    echo "File not found!"
fi
    
Top comments (0)