Linux And Unix Command To View File

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? Also, How do I list the files in a directory stored on my Unix box?

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.

Linux And Unix Command To View File

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix system
Est. reading time 2m
  • 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
cat /etc/resolv.conf
Sample outputs:


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 foo-bar.mp3
gnome-open mars-video.mp4

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 foo-bar.mp3
kde-open mars-video.mp4

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

xdg-open file.pdf
xdg-open foo-bar.mp3
xdg-open mars-video.mp4

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

open file.pdf
open sai-ram-bhjan.mp3
open mars-video.mp4

How do I list the files in a directory on Unix?

To see or list the files in a directory on Linux, run ls command:
ls -l

If you would like to see and list files in another directory, use the ls along with the path to the directory:
ls /usr/
ls -l /etc/
## just list resolv.conf file #
ls -l /etc/resolv.conf

Common ls command options

The syntax is:
ls [options] file
Where options for ls are:

  • -l : Use a long listing format to display Linux/Unix file names.
  • -a : Do not ignore entries starting with . (period). Display all hidden files.
  • -d : List Linux directories themselves, not their contents
  • -R : List sub-directories recursively on Linux
  • -F : Append indicator for file. For example, / for directories, * for executable Linux files, @ for symbolic links and more

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • venureddy Apr 28, 2014 @ 11:17

    Good Stuff

  • Steve DenHerder May 15, 2014 @ 5:16

    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.

  • Mark Kenny Jun 4, 2014 @ 18:28

    Don’t forget: tac

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

  • saturn 1 Sep 30, 2014 @ 21:07

    this sucks to high heaven,,linix is a pain in arse,,i dont know why anyone would use a fool system like this,,terminals suck,,i do mwean suck,,,terminals,,,idiots,,my windows got imploded,,i had to download this ubuntu,,i regret every god dam day of it,,i cant open any files,,cant open downloads or find them,,cant do anything on this,,,i dont know how or where to look,,terminal???/what the f is that,,how do you work it,,i checked on how to work this,,,just god dam crap,,you have to go to a college for hackers to know what all this shit is to work your browser,l,,,who ever made this for the common people,,,LIED,LIED,,,this is not for peopole,,its for hackers,,i tried to load windows on it,,it dont even let the software load,,i gues i9 have to delete this shit and then download,,this is shit,,i cant open a zip file,,i go to terminal and dont know what the fuck in doing in terminal,,,i check and forum say to put in different signalas or symbols i never seen before,,screw this and the dog it road in on,,,you ubuntu people are a bunch of crooks wanting to charge free for this,,,yes free is way to much money for this.

    • kojaq Jun 24, 2015 @ 8:35

      The cake is a lie.

      The article on the other hand is great. Might use the addition of the most commonly used parameters.
      Anyway, thanks. I was like “more” (mooar) :-) but forgot that you’re often satisfied with “less”

  • aref ghobadi Aug 15, 2015 @ 14:04

    thanks a lot

  • ti505 Nov 6, 2020 @ 20:22

    Very useful and handy command to open and view files on Ubuntu desktop. thank you very much

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum