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)