Free Hosting Online for WorkStations

< Previous | Contents | Next >

The same goes for filenames containing a space:


cat This\ File


3.3.4. More ways to view file content


3.3.4.1. General


Apart from cat, which really doesn't do much more than sending files to the standard output, there are other tools to view file content.


The easiest way of course would be to use graphical tools instead of command line tools. In the introduction we already saw a glimpse of an office application, OpenOffice.org. Other examples are the GIMP (start up with gimp from the command line), the GNU Image Manipulation Program; xpdf to view Portable Document Format files (PDF); GhostView (gv) for viewing PostScript files; Mozilla/FireFox, links (a text mode browser), Konqueror, Opera and many others for web content; XMMS, CDplay and others for multimedia file content; AbiWord, Gnumeric, KOffice etc. for all kinds of office applications and so on. There are thousands of Linux applications; to list them all would take days.


Instead we keep concentrating on shell- or text-mode applications, which form the basics for all other applications. These commands work best in a text environment on files containing text. When in doubt, check first using the file command.


So let's see what text tools we have that are useful to look inside files.


Font problems

Plain text tools such as the ones we will now be discussing, often have problems with "plain" text files because of the font encoding used in those files. Special characters, such as accented alphabetical characters, Chinese characters and other characters from languages using different character sets than the default en_US encoding and so on, are then displayed the wrong way or replaced by unreadable rubbish.


These problems are discussed in Section 7.4.


3.3.4.2. "less is more"


Undoubtedly you will hear someone say this phrase sooner or later when working in a UNIX environment. A little bit of UNIX history explains this:


First there was cat. Output was streamed in an uncontrollable way.

Then there was pg, which may still be found on older UNIXes. This command puts text to the output one page at the time.

The more program was a revised version of pg. This command is still available on every Linux system.

less is the GNU version of more and has extra features allowing highlighting of search strings, scrolling back etc. The syntax is very simple:


less name_of_file


More information is located in the Info pages.


You already know about pagers by now, because they are used for viewing the man pages.


3.3.4.3. The head and tail commands


These two commands display the n first/last lines of a file respectively. To see the last ten commands entered:


tony:~> tail -10 .bash_history locate configure | grep bin man bash

cd xawtv &

grep usable /usr/share/dict/words grep advisable /usr/share/dict/words info quota

man quota echo $PATH frm

tony:~> tail -10 .bash_history locate configure | grep bin man bash

cd xawtv &

grep usable /usr/share/dict/words grep advisable /usr/share/dict/words info quota

man quota echo $PATH frm

Top OS Cloud Computing at OnWorks: