Linux And Unix Command To View File

by on April 17, 2014 · 3 comments· LAST UPDATED April 17, 2014

in , , , ,

I am a new Linux bash shell command line user. How can I view a text file using command line on a Linux or Unix-like operating systems? How can I view (open) binary files such as PDF or images on a Linux or Unix like system from command line?

You can use any one of the following command to view a text file or any other files such as PDF, doc, image, video, music/mp3 and more.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Estimated completion timeN/A
  • cat command
  • less command
  • more command
  • gnome-open command or xdg-open command (generic version) or kde-open command (kde version) - Linux gnome/kde desktop command to open any file.
  • open command - OS X specific command to open any file.

View a text file called foo.txt on a Linux or Unix-like systems

Open the Terminal application and type the following command to view a text file called foo.txt using cat command:

 
cat foo.txt
 

OR

 
cat /etc/resolv.conf
 

Sample outputs:

nameserver 101.1.2.3
nameserver 102.2.3.4

You can also use more or less command as follows:

 
less filename
more filename-here
 

gnome-open: Open files and directories/urls

The gnome-open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. The syntax is:

 
gnome-open file.pdf
gnome-open sai-ram-bhjan.mp3
gnome-open mars-video.mp4
gnome-open http://www.cyberciti.biz/
 

See our faq "Open Gnome Nautilus File Manager For The Current Linux / Unix Command Line" for more information.

If you are using KDE desktop try kde-open command as follows:

 
kde-open file.pdf
kde-open sai-ram-bhjan.mp3
kde-open mars-video.mp4
kde-open http://www.cyberciti.biz/
 

Another option is to try out xdg-open command on Linux and Unix desktop:

 
xdg-open file.pdf
xdg-open sai-ram-bhjan.mp3
xdg-open mars-video.mp4
xdg-open http://www.cyberciti.biz/
 

If you are using OS X Unix try open command as follows:

 
open file.pdf
open sai-ram-bhjan.mp3
open mars-video.mp4
open http://www.cyberciti.biz/
 
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 venureddy April 28, 2014 at 11:17 am

Good Stuff

Reply

2 Steve DenHerder May 15, 2014 at 5:16 am

Sometimes the ‘ strings ‘ command is useful if the file is not all text. I seems to pull out text but leave the no text out.

Reply

3 Mark Kenny June 4, 2014 at 6:28 pm

Don’t forget: tac

Although I’ve yet to find a useful purpose for it

Reply

Leave a Comment

Tagged as: , , ,

Previous Faq:

Next Faq: