• Aucun résultat trouvé

Search the Ubuntu file system

Dans le document Prepared exclusively for J.S. Ash (Page 134-137)

A little known fact is that the average human spends a high proportion of her/his time looking for things that have been lost. Ubuntu helps avoid this, at least in computing terms, by including a number of pow-erful file search functions for both command-line and GUI users.

Command-line searching

There are essentially two methods used to search for files at the command-line:locateandfind. The difference is thatlocaterelies upon a database of files and locations, whilefind literally searches the file system each time you use it.

locateis partnered to a back-end program—updatedb—that is run peri-odically and automatically by the system to update the database of files.

This highlights a weakness of the system—locate’s results are only as good as the last time the database was updated. Therefore it’s often a good idea to manually update the database using the updatedb com-mand (as root—sudo updatedb) before using locate. There are several different versions of the locate software and the version provided with Ubuntu—calledmlocate—is designed to update its database quickly by

SEARCH THEUBUNTU FILE SYSTEM 135

only looking for and adding new files. This meansupdatedbdoesn’t take long to run each time.

Using locate is easy. Just type locate and then the search word, or search phrase. If the search phrase includes symbols or spaces, enclose it in quotation marks. For example, to search for any files or folders that includefstabin their names, you would typelocate fstab. To search for the fileaccounts 2008.xls, you might typelocate "accounts 2008".locate can use wildcards. To search for any MP3 files on the system, you could typelocate *.mp3.

Usingfindis a little different. First you must specify the search location and then the search term. For example, to search for the fileaccounts 2008.xls in your /home directory, you could type find /home/username -name "accounts 2008". You should replaceusernamewith your own details.

To search the entire file system, specify the file system root instead:find / -name "accounts 2008".

Bothlocateandfinduseregular expressions(known asregexes) to spec-ify search terms. It’s beyond the scope of this book to go into this rather arcane field but several very good beginner guides can be found by searching Google. Regexes permeate all of Linux and spending some time learning how to use them can be very rewarding.

Searching at the desktop

Ubuntu includes the Tracker tool for all desktop searching needs. Like recent developments in Mac OS X and Vista, this is designed to catalog all kinds of data, above and beyond just files. Recently visited websites are cataloged, for example, as are programs installed on the system.

Tracker also indexes the contents of emails and also files (provided it understands the file format). Thus a PDF file containing a certain phrase can be searched for, even if its filename is obscure and/or unre-lated.

Thus Tracker can actually be an alternative access point for day-to-day use of Ubuntu. Rather than using Nautilus to navigate to a file in the Documentsdirectory, simply open a Tracker window and type its name (or part of its name). Then double-click to open it. Rather than clicking Applications→Office→OpenOffice.org Writer, just typewriterand then double-click the program that appears in the search results.

Tracker isn’t enabled by default in Ubuntu 8.04 Hardy Heron because some believe it can slow the system down. It runs a background service

SEARCH THEUBUNTU FILE SYSTEM 136

Figure 3.20: Tracker (see Tip77, on page134)

that’s always monitoring the file system and thereby using resources, and it also performs an indexing run each time you log in. That said, many report no problem using it, and there’s little reason to give it a try. The same steps below that describe how to enable it can also be used to disable it.

Before activating it, it’s a good idea to install the wv package using Synaptic. This allows Tracker to index the contents of Word documents (.docfiles). Then, to activate the Tracker service, click System → Pref-erences → Search and Indexing, and click the check boxes alongside Enable indexing and Enable watching. If you’re using a notebook, you might also want to check the box alongside Disable all indexing when on battery.

Click the OK button. You’ll be told the tracker daemon has to restart.

This is fine. Following this, a new magnifying glass icon will appear in the panel. Clicking this provides access to Tracker’s search tool. How-ever, you can’t use it just yet! First, you must let Tracker index your hard disk and files. This might take some time. You’ll know when it’s finished because the Tracker icon will change to an orange magnifying

REMOVE THEBAD PASSWORDWAIT PERIOD 137

glass, rather than a clear one. In future the glass might change again but this simply indicates that Tracker is “catching up”; you’ll still be able to search.

To use Tracker, just click its panel icon, type the search term (or phrase, if you want to search for content within documents), and then click the Find button. The categories of search results will be listed on the left of the program window (actual files, folders, applications, documents, and so on), and the specific search results will be listed on the right.

To open any file or folder, simply double-click it. See Figure3.20for an example.

Tracker can also be used from the command-line, once Synaptic has been used to install the tracker-utils package. Once the package has installed, just typetracker-searchfollowed by your search term.

Dans le document Prepared exclusively for J.S. Ash (Page 134-137)