Viewing file content

So far, we've only looked at the covers, without opening the book. Let's give you an overview of ways of getting to know what's in a file.

The file command

Gives the type of data based on code at the beginning of the file. Note that file is not perfect, it only tries an educated guess. In the example below, for instance, file makes no difference between verlanglijst and, although the first is just ordinary text, while the second is a shell script.

tille:~>file mail
mail: directory

tille:~>file verlanglijst 
verlanglijst: ASCII text

tille@sprawl:~>file nbroc2001.pdf
nbroc2001.pdf: PDF document, version 1.2

tille@sprawl:~>file training/unix-basics/
training/unix-basics/ PostScript document text conforming at level 2.0

tille@sprawl:~>file Verlofkaart2001MGA.xls
Verlofkaart2001MGA.xls: Microsoft Office Document

tille@sprawl:~>file images/me+tux.jpg
images/me+tux.jpg: JPEG image data, JFIF standard

tille@sprawl:~>file training/unix-basics/book1.html
training/unix-basics/book1.html: HTML document text

tille@sprawl:~>file richtlijnen.doc
richtlijnen.doc: Microsoft Office Document

tille:~>cd /bin

tille:/bin>file gzip
gzip: ELF 32-bit LSB executable, Intel 80386, version 1, ... 

tille:/bin>cd /usr/lib

tille:/usr/lib>file ELF 32-bit LSB shared object, Intel 80386, ... 

tille:/usr/lib>file ASCII English text

tille:/usr/lib>cd /boot/

tille:/boot>file kernel.h
kernel.h: symbolic link to kernel.h-2.4.2

tille:/boot>file vmlinuz-2.4.2-2 
vmlinuz-2.4.2-2: x86 boot sector

tille:/boot>cd /etc

tille:/etc>file profile
profile: ASCII text

The cat command

Concatenates files (puts them together) and puts them to the output, with only one argument given cat will display the contents of the file

tille:~>cat test1
some words
tille:~>cat test2
some other words
tille:~>cat test1 test2
some words
some other words

The more, less and pg commands

While cat puts all output all at once to the screen, more filename allows to view the output page by page. Navigate through the output using the spacebar and the b-key (back).

Some systems offer the GNU less command, which has more extended features than more. "Less is more", you will hear somebody say sooner or later. less allows vi-like browsing and searching in the text. See Chapter 4: Editors for more information about the vi editor.

On some really old systems, you will find neither more nor less. The system might provide the pg utility, which provides similar functionality. Navigate to the next page pressing the enter-key.


Quitting the output of more, less and pg without going all through the file is done pressing "q".

Viewing file content in X Windows

If in a graphical user environment, there are all sorts of editors and viewers that come with the system. Consult your system documentation and find your favorite.