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)