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 filename
ormore filename
β Opens the file in a paginated viewer. -
nano filename
β Opens in the nano text editor. -
vi filename
orvim 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 filename
okular filename
xdg-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)