And while traditionally text files were managed with command-line tools and text editors, the focus of this chapter is on introducing graphical tools such as gedit.. ■ Tip Most program R
Trang 2Type of Program Windows Ubuntu Alternative Choices
www.abisource comwww.koffice.org/kword
www.gnome.org/projects/ gnumeric
www.koffice.org/kspread
www.koffice.org/kpresenter
www.inkscape.org
www koffice org/karbon
www.knoda.org
http://kompozer.net/www.w3.org/Amaya
www.mozilla.comhttp://kontact.kde.org/kmailwww.kontact.kde.org
www.konqueror.org
www.google.com/chromewww.twotoasts.de
www.opera.comwww.k3b.org
http://aqualung.factorial hu
http://banshee-project.org
Trang 3CHAPTER 11 A WORLD OF APPLICATIONS
http://nostatic.org/grip
www.videolan.orgwww.mplayerhq.hu/homepage
www.koffice.org/krita
www.kdenlive.org
orange.fr/coquelle/karchiver cmd.exe
http://pagesperso-command.exe
www.x.org
www.kate-editor.org
xterm
Trang 4LINUX HAS IT ALL
The Ubuntu software archives contain thousands of programs to cover just about every task you mightwant to accomplish on your computer Diversity is vitally important within the Linux world For example,rather than just one e-mail program, you’ll find many available They compete with each other in a gentleway, and it’s up to you which one you settle down with and use
Part of the fun of using Linux is exploring what’s available Of course, the added bonus is that virtually allthis software is free of charge, so you can simply download, install, and play around If you don’t like aprogram, just remove it from your system However, don’t forget to revisit the program’s home page after
a few months; chances are the program will have been expanded and improved in that short period, and itmight be better at meeting your needs
A Quick Start with Common Ubuntu Programs
Trang 5CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-1 OpenOffice.org Writer
Trang 6
Note OpenOffice.org is covered in more detail in Chapter 13
Tip In all the OpenOffice.org applications, you can hover the mouse cursor over each button for one second to
see a tooltip showing what it does
Trang 7CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-2 OpenOffice.org Calc
Trang 8
Figure 11-3 OpenOffice.org Impress
Trang 9CHAPTER 11 A WORLD OF APPLICATIONS
.ppt.swf
Trang 10
Figure 11-4 OpenOffice.org Base
Trang 11CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-5 Evolution
Trang 12Figure 11-6 Mozilla Firefox
Tip When Firefox starts, tabs aren’t activated If you would like to keep tabs in view all the time, click Edit
Preferences, click the Tabs button, and then put a check alongside Always Show the Tab Bar
Trang 13CHAPTER 11 A WORLD OF APPLICATIONS
Trang 14Note Unlike iTunes, Rhythmbox can’t play Digital Rights Management (DRM)-protected files, including standard
tracks bought through the iTunes Music Store iTunes, Amazon.com, and others offer music not encumbered withDRM, and these, as well as music you’ve ripped from CDs, will play perfectly
Trang 15CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-8 Totem movie player
Trang 16
Tip Most modern CD/DVD recorders utilize burn-proof technology, which helps ensure error-free disc creation
To activate this for the Nautilus CD/DVD Creator, open a terminal window (Applications Accessories Terminal)
check in Search Also in Key Names In the search results at the bottom of the window, click the first result (/apps/nautilus-cd-burner/burnproof) and make sure there’s a check in burnproof at the top right of the window Then close the configuration editor
Figure 11-9 Nautilus CD/DVD Creator and Brasero
Trang 17CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-10 GIMP
Other Handy Applications
Trang 18Figure 11-11 GNOME Calculator
Trang 19CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-12 Archive Manager
Collaborative International
Dictionary
Trang 20
Figure 11-13 Dictionary
Trang 21
CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-14 Empathy
Trang 22
Figure 11-15 Ekiga
Trang 23
CHAPTER 11 A WORLD OF APPLICATIONS
Figure 11-16 Mines
www.winehq.org
Trang 24Figure 11-17 Wine
Summary
Trang 25C H A P T E R 12
■ ■ ■
265
Working with Text Files
Windows views text files as just another file type, but to Ubuntu (and to the whole Linux family in fact), they are the very fabric of which the system is made Configuration files and program documentation are stored as plain text This is clearly different from Windows, where any information you’re supposed to
read will likely be contained in a Windows help file, a rich text format (RTF) file, or even a Microsoft
Word document
So important are text files to Linux that for a long time you could have been caught in a heated
debate over which text editor was the best! And while traditionally text files were managed with
command-line tools and text editors, the focus of this chapter is on introducing graphical tools such as gedit No doubt one day you will get to grips with command-line text editors such as Vim, Emacs, or
even both—but right now the thing is to get you up and running with Lucid Lynx!
It’s worth mentioning that text files under Linux usually don’t have a file extension Unlike with
Windows or other OSs, the txt file extension is rarely used Sometimes a conf extension is added to
plain text configuration files, but more often text files have no extension at all
Text: A History Lesson
Given this reliance on text and text files, it has always been very important for Linux administrators and power users alike to have powerful text-manipulation tools at their fingertips
■ Tip Most program README files, along with other assorted documentation, can be found in a directory named
Piping and Redirecting
When you execute a command in a terminal window (which was—and for many people still is—an
everyday task), output is usually produced in the form of a text stream So the same techniques that
apply to text files can be also used on this output, with a simple operation called piping Piping is the
process of sending the output of a command as the input for another command, usually a
text-manipulation tool That output is then manipulated as if it were a file Powerful!
We’ll illustrate this with an example using grep grep is a tool that takes text as its input, searches
and tries to match a regular expression or piece of text, and prints the lines that contain that regular
Trang 26266
through Applications ➤ Accessories ➤ Terminal):
grep Linux operatingsystems.txt
grep will look for the text “Linux” in the file operatingsystems.txt and print only the lines that contain that text So grep works with text files to filter lines in a file based on criteria you set
But what if you want to do the same thing not to a text file, but to the output of a command? You use piping, which is expressed by the character | It instructs a command to send its output to another command (and to the second command to take that as its input) For example, if you want to find a particular process—say, the process gedit (processes are listed with the ps command)—you’d type the following at the command line:
ps -d | grep gedit
This command will show you information about the gedit process (if it is running)
Another way of attaining a similar end is by means of redirecting—expressed with the character >
Redirecting means sending the output of a command to a text file So the preceding task could be fulfilled by executing two commands: one for listing process information (and redirecting its output) and the other to display only the lines that pertain to a certain process:
ps -d > processes.txt
grep gedit processes.txt
STANDARD INPUT AND OUTPUT
If you’ve read any of the Ubuntu man pages, you might have seen references to standard input and
standard output Like many things in Linux, this sounds complicated, but is merely a long-winded way of referring to something that is relatively simple (although the terms have specific meanings to
programmers) Standard input is simply the device that programs running under Ubuntu normally take input from In other words, on the majority of desktop PCs, when you’re using the command-line shell, standard input refers to the keyboard However, it’s important to note that it could also refer to the mouse
or any other device on your system capable of providing input; even some software can take the role of providing standard input
Standard output is similar It refers to the device to which output from a command is usually sent from software In the majority of cases at the command line, this refers to the monitor screen, although it could
be any kind of output device, such as your PC’s sound card and speakers
In other words, for the majority of desktop Ubuntu installations, it will combine (concatenate) any number
of files together and print the results on the screen If you specify just one file, it will display that single file
Trang 27CHAPTER 12 ■ WORKING WITH TEXT FILES
grep The grep command searches for regular expressions or text patterns in a text file or
command output, and prints only matching lines The name is derived from
“global/regular expression/print.” Use grep if you want to filter lines based on the
presence of a word
sed Short for “stream editor,” as its name implies, this transforms a text stream based on
specified rules and criteria Use sed if you want to search and replace a word in a text file or modify the output of a command
awk AWK, whose name derives from the family names of its creators (Alfred Aho, Peter
Weinberger, and Brian Kernighan), is a powerful text-manipulation programming
language As Alfred Aho puts it, “AWK is a language for processing files of text A file is
treated as a sequence of records, and by default each line is a record Each line is broken up into a sequence of fields, so we can think of the first word in a line as the first field, the
second word as the second field, and so on An AWK program is of a sequence of
pattern-action statements AWK reads the input a line at a time A line is scanned for each pattern in the program, and for each pattern that matches, the associated action is executed.” It is
used, for example, to print specified columns of a text file
cat This is a UNIX command used to display and concatenate text files You can, for example,
merge two text files into a third file
head This is used to display just the first lines of a text file
tail This is used to display just the last few lines of a text file
more This is a command-line utility used to display the contents of a text file one screen at a
time
less This command lets you move backward in the document
sort This tool is used to sort the lines in a text file or stream in forward or reverse order
diff This tool is used to compare two text files and print the differences between them It’s
useful if you are comparing, for example, two versions of the same source code
Trang 28268
■ Note The less and more commands are sometimes known as pagers because of their ability to let you scroll
through pages of text You might still hear them referred to as such in the wider Linux community, although the term has fallen out of use
Bash is an incredibly capable tool when it comes to text manipulation, and some of its tool set offers modest word processing–like functionality It’s no wonder that some people live their lives working at the Bash prompt and have no need of sophisticated GUI tools!
Table 12-2 lists some more text-processing tools that you can use on the command line Along with the commands are listed any command options needed to make them work in a useful way Some commands rely on redirection and piping, which were explained earlier in this chapter
■ Note Most text-processing tools under Bash were created for programmers, so some options might seem a little
odd when you read the man pages However, all the tools are extremely flexible and offer functions for every kind
of user
Table 12-2 Useful Text-Processing Commands
Spell-check aspell -c filename Highlights any questionable words within filename, and
offers a choice of replacements, rather like a standard word processor’s spell-checker Press X if you wish to exit after spell-checking starts
Single word
spell-check
look word Looks up word in the dictionary; if the word is displayed in
the output, the word has been found If not, the word hasn’t been found Note that this command returns loose matches—searching for test, for example, will return every word beginning with test (testing, testimony, testosterone, and so forth)
Word count wc -w filename Outputs the number of words in filename Used without
the -w command switch, wc outputs the number of lines, followed by the word count, followed by the number of bytes in the file
Remove line
breaks fmt filename > newfile Creates newfile, removing breaks at the ends of lines in
filename Double line breaks between paragraphs aren’t
affected Adding the -u command switch removes instances of double spaces too
Trang 29CHAPTER 12 ■ WORKING WITH TEXT FILES
269
Join two files paste file1 file2 >
file3 Creates file3 by joining file1 and file2 side by side
(effectively creating two columns of text) Each line is separated by a tab
Word wrap fold -sw20 filename >
newfile
Creates newfile from filename, wrapping lines at the
specified 20 characters (increase/decrease this value for shorter/longer lines) Note that the -s switch ensures that lines don’t break across words, even if this means exceeding the specified character count
Add line
numbers nl filename > newfile Creates newfile from filename, adding line numbers to
the beginning of each line
Sort list sort file1 > file2 Creates file2 from file1, sorting its contents
alphanumerically (technically, it sorts according to ASCII,
so some symbols appear above numbers) For obvious reasons, this command works best on lists
If none of this makes sense to you, it doesn’t matter, because you will seldom need to use this
knowledge for everyday tasks But it is an interesting insight to know that there’s more to Linux than
meets the eye!
The Text Editor Wars
A variety of text editors can be used within the shell, but three stand out as being ubiquitous: ed, Vim,
and Emacs The first in that list, ed, is by far the simplest That doesn’t necessarily mean that it’s simple
to use or lacks powerful features, but it just doesn’t match the astonishing power of both Vim and
Emacs To call Vim and Emacs simple text editors is to do them a disservice, because both are extremely powerful interactive environments In particular, Emacs is considered practically an OS in itself, and
some users of Linux treat it as their shell, executing commands and performing everyday tasks, such as reading and sending e-mail from within it There are entire books written solely about Emacs and Vim
■Tip A fourth shell-based text editor found on many Linux systems is nano This offers many word processor–like
features that can be helpful if you’ve come to Linux from a Windows background
The downside of all the power within Emacs and Vim is that both packages can be difficult to learn
to use They’re considered idiosyncratic by even their most ardent fans Both require the user to learn
certain unfamiliar concepts, as well as keyboard shortcuts and commands
Although there are debates about which text editor is better and which is best, it’s generally agreed that Vim offers substantial text-editing power but isn’t too all-encompassing It’s also installed by default
on Ubuntu On Ubuntu, Emacs must be installed as an optional extra Both text editors are normally
available on virtually every installation of Linux or UNIX We’ll concentrate on using Vim here
Trang 30270
there are many versions and updates of vi The original program, once supplied with UNIX, is rarely used
nowadays Vim is the most commonly used clone; Vim stands for vi improved Another version is elvis
(http://elvis.the-little-red-haired-girl.org) However, most people still refer to Vim and elvis as vi, even though they are entirely new pieces of software
■ Note There used to be a constant flame war between advocates of vi and Emacs, as to which was better This
could be quite a vicious and desperate debate, and the text editor you used was often taken as a measure of your character! Nowadays, the battle between the two camps has softened, and the Emacs vs vi debate is considered
an entertaining cliché of Linux and UNIX use When users declare online which text editor they prefer, they often include a smiley symbol to acknowledge the once-fevered emotions
Working with Text Files
Fortunately, you don’t need to learn how to use those tools if you don’t feel like it, because Ubuntu
comes equipped with a powerful, and yes, graphical, text-editing tool: gedit gedit is in fact the default
text editor for the GNOME desktop environment, so you can find it in other distributions of Linux such
as Fedora and SUSE
Introducing gedit
The basic interface of gedit, as you can see in Figure 12-1, is quite similar of that of Notepad, and in many regards the two applications work very much alike But gedit has some salient features, such as plug-in support, that raise it above the crowd of simple text-editing tools like Notepad You’ll see that there are a lot of available plug-ins for gedit that will enable you to do things you can only dream of doing with other text editors In this respect, it is a tool that honors the history of Linux; it isn’t just a simple GUI replacement for Vim or Emacs
Trang 31CHAPTER 12 ■ WORKING WITH TEXT FILES
271
Figure 12-1 gedit: A simple yet powerful graphical text editor
One of the neat features is the ability to work with tabs, just like in your favorite web browser Each
tab is an open text file So when you are, for example, writing a script or taking notes, you can have Don Quixote, the classic novel by Spanish writer Miguel de Cervantes Saavedra, open in another tab to take
short breaks from work!
The gedit window has the following elements:
Menubar: The menubar gives you access to all gedit commands
Toolbar: Using the toolbar you can perform common tasks such as creating, opening, and saving
text files
Display area: The display area is where the action is! This is where the text is actually displayed
Statusbar: The statusbar, shown at the bottom of the window, displays information about current
activity and contextual menus
Side Pane: The side pane displays a list of open documents, and other information depending on
which plug-ins are enabled By default, the side pane is not shown To show it, choose View ➤
Side Pane
Trang 32272
By default, the bottom pane is not shown To show it, choose View ➤ Bottom Pane
To start gedit, simply go to Applications ➤ Accessories ➤ gedit Text Editor, or right-click a text file and select “Open with gedit.” It is also very likely that if you double-click a text file it will automatically
be opened with gedit
Opening gedit with those methods assumes that you will edit the file with your everyday user account But what if you want to edit a configuration file to which only superusers have access? Normal users will only be able to open it in read-only mode, meaning that they will be unable to save the
changes they make To edit configuration files, press Alt+F2 to invoke the Run Command dialog box and
type gksu gedit in the text field After entering your password, gedit will open with root-like privileges
The basic operations are simply explained You have the buttons on the toolbar and the options in the menus To create a new file, just click File ➤ New, and a new tab will be created with a blank
document (the same happens if you click the New button on the toolbar) To open an existing file, click File ➤ Open…, and a dialog box will let you browse for the text file to open Finally, click File ➤ Save to store the results of your work to the disk
Once you have the desired file in your display area, you can begin to work as with any text editor You can write new text, select chunks of text and copy it to the clipboard, or paste text from other sources You cannot apply formatting to parts of the file, since gedit is only a text editor, not a word processing tool such as OpenOffice.org’s Writer What you save are text files, and because of this gedit is fully interoperable with Notepad
gedit saves the history of recently opened files, which you can see by expanding the File menu or clicking the small arrow next to the Open button in the toolbar If you click a file, it will open once again
Working with gedit
Working with gedit is just a matter of entering text in the display area and saving the file from time to time While simple, it does offer plenty of options that can make your tasks easier and more enjoyable The menubar gives you access to all the operations that can be performed with gedit Table 12-3 lists all the options available in the menubar You can open a test file and play a little with those options to familiarize yourself with them You can also use the Personalize dialog box to modify the program’s general behavior
Table 12-3 The Menubar Options
File New Creates a new text file from scratch
Open… Allows you to browse your disk and open an existing text file
Save Stores the changes you have made to the file on the disk You need to
have write permissions on the file to do this
Save As… Allows you to save your file with a different name or to an alternate
location It’s useful if you don’t have write permissions on the file or if want to save several versions of the same file
Revert Undoes all changes made to the document since the last time you
saved it
Trang 33CHAPTER 12 ■ WORKING WITH TEXT FILES
273
Print Preview Displays how the document will be printed As this is not a word
processor, there wouldn’t be much surprises here, but at least you would
be able to anticipate how many pages the document has
Print… Actually prints the file
List of files Lists the recently opened files Click a file to open it again
Close Closes only the current document You will be asked whether you want to
save it beforehand
Quit Quits gedit All documents can be saved beforehand
Edit Undo Undoes the last change
Redo Redoes the last undone change
Cut Copies the selected text to the clipboard and deletes it from the file
Copy Copies the selected text to the clipboard without deleting it from the file Paste Inserts the contents of the clipboard into the current file
Delete Deletes the selected text from the file without copying it to the clipboard Select All Selects all text in the file so you can later copy, cut, or delete it
Preferences Gives you access to the Preferences dialog box (explained later in this
chapter)
View Toolbar Shows or hides the toolbar It is selected by default
Statusbar Shows or hides the statusbar It is selected by default
Side Pane Shows or hides the side pane It is disabled by default
Bottom Pane Shows or hides the bottom pane It is disabled and grayed out by default
Some programming functions will allow you to enable it
Fullscreen Switches to full-screen mode for easier editing Change back to normal